Page 1 of 1

About Question enthuware.ocpjp.v7.2.1302 :

Posted: Mon May 06, 2013 3:15 pm
by aspire_jp
Hey,
If we use TreeMap the Book must be Comparable. But as nothing of this sort is mentioned the 2nd option //replace line 1 may not be correct.
Thanks!

Re: About Question enthuware.ocpjp.v7.2.1302 :

Posted: Mon May 06, 2013 6:00 pm
by admin
Since the code for Book class is not given, you have to assume that it is compatible with options that are otherwise valid. It is not possible to specify everything in the problem statement and reasonable assumptions have to be made. For example, the Book class should also implement hashCode and equals sensibly but that is also not given in the questions. In that case all the options would be invalid!

HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1302 :

Posted: Tue Aug 13, 2013 4:34 am
by laura90_m@yahoo.com
An option is represented by

Code: Select all

Replace line //4 and //5 with:
Integer i = map.get(b); 
return i == null? 0:i;
But the explanation says that
This change is fine but it is not required because it has nothing to do with generics.
Yes, there is no need to change //4 and //5, because the generics also support the old code. But I would say that the change IS related to generics, because the cast was removed, and this happened because generics is used.

Re: About Question enthuware.ocpjp.v7.2.1302 :

Posted: Tue Aug 13, 2013 9:07 am
by admin
I see your point, Laura. The explanation has been modified accordingly.

thank you for your feedback!
Paul.