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!
About Question enthuware.ocpjp.v7.2.1302 :
Moderators: Site Manager, fjwalraven
-
- Posts: 8
- Joined: Wed Apr 17, 2013 12:37 pm
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1302 :
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.
HTH,
Paul.
-
- Posts: 3
- Joined: Sun Apr 14, 2013 12:02 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1302 :
An option is represented by
But the explanation says that
Code: Select all
Replace line //4 and //5 with:
Integer i = map.get(b);
return i == null? 0:i;
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.This change is fine but it is not required because it has nothing to do with generics.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1302 :
I see your point, Laura. The explanation has been modified accordingly.
thank you for your feedback!
Paul.
thank you for your feedback!
Paul.
Who is online
Users browsing this forum: No registered users and 1 guest