For this question the declaration
ArrayList<Double> al = new ArrayList<>();
is itself incorrect (Type mismatch: cannot convert from ArrayList<?> to ArrayList<Double>)
We need to declare like below
ArrayList<Double> al = new ArrayList<Double>();
About Question enthuware.ocajp.i.v7.2.925 :
Moderators: Site Manager, fjwalraven
-
- Posts: 27
- Joined: Thu Feb 07, 2013 9:46 pm
- Contact:
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.925 :
Please make sure you are using JDK 7 for compilation.
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Wed Feb 05, 2014 3:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.925 :
Shouldn't the explanation of the correct answer "System.out.println(al.indexOf(1.0));" be :
"ArrayList.indexOf takes Object as parameter"
instead of :
"1.0 is a double and so it can be boxed into a Double object."
?
"ArrayList.indexOf takes Object as parameter"
instead of :
"1.0 is a double and so it can be boxed into a Double object."
?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.925 :
No, in the given code, al is declared as ArrayList<Double>. So indexOf and add will require Double (not Object). That is why the explanation says that 1.0 will be boxed into a Double.
Explanation has now been enhanced to explain this point.
thank you for your feedback!
Explanation has now been enhanced to explain this point.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Wed Feb 05, 2014 3:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.925 :
But the following code runs and uses ArrayList.indexOf(Object) :
ArrayList<Double> list = new ArrayList<>();
System.out.println(list.indexOf("test"));
ArrayList<Double> list = new ArrayList<>();
System.out.println(list.indexOf("test"));
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.925 :
I see your point now. You are right. This has now been fixed.
thank you for your feedback!
Paul.
thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 134 guests