Page 1 of 1

About Question enthuware.ocajp.i.v7.2.925 :

Posted: Thu Mar 07, 2013 5:14 pm
by Sweetpin2
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>();

Re: About Question enthuware.ocajp.i.v7.2.925 :

Posted: Thu Mar 07, 2013 7:12 pm
by admin
Please make sure you are using JDK 7 for compilation.

Re: About Question enthuware.ocajp.i.v7.2.925 :

Posted: Wed Feb 05, 2014 4:01 pm
by JackBo
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."

?

Re: About Question enthuware.ocajp.i.v7.2.925 :

Posted: Wed Feb 05, 2014 9:54 pm
by admin
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!

Re: About Question enthuware.ocajp.i.v7.2.925 :

Posted: Wed Feb 12, 2014 2:06 pm
by JackBo
But the following code runs and uses ArrayList.indexOf(Object) :

ArrayList<Double> list = new ArrayList<>();
System.out.println(list.indexOf("test"));

Re: About Question enthuware.ocajp.i.v7.2.925 :

Posted: Wed Feb 12, 2014 9:05 pm
by admin
I see your point now. You are right. This has now been fixed.

thank you for your feedback!
Paul.