Page 1 of 1

About Question enthuware.ocpjp.v8.2.1725 :

Posted: Sat Nov 07, 2015 6:22 am
by morpana
Shouldn't the correct answer be compare as in fourth answer, and not compareTo (second answer) as it is now.

Re: About Question enthuware.ocpjp.v8.2.1725 :

Posted: Sat Nov 07, 2015 8:59 am
by admin
Why do you think so?

Re: About Question enthuware.ocpjp.v8.2.1725 :

Posted: Thu Oct 12, 2017 3:12 pm
by nieckq
admin wrote:Why do you think so?
Because, as it even says in the answer, Comparable has the compareTo(T t) method, and the Comparator makes you implement the compare(Obj obj1, Obj obj2) method. In this case because Person does not implement comparable, we want to sort the collection using a Comparator. Hence we use the compare(Obj obj1, Obj2 obj) method and not compareTo(T t).

Re: About Question enthuware.ocpjp.v8.2.1725 :

Posted: Thu Oct 12, 2017 9:02 pm
by admin
If you look closely, Option 2 does use compare method (and not compareTo) to compare Person objects.

The compareTo method is used to compare only the the dob field inside the implementation of the compare method. This has nothing to do with Comparator. String class implements Comparable and not Comparator.

String class does not have compare method and that is why option 4 is incorrect.

Re: About Question enthuware.ocpjp.v8.2.1725 :

Posted: Wed Mar 21, 2018 12:04 pm
by Wesley
That one got me too for exactly the same reason. Sneaky sneaky..

Re: About Question enthuware.ocpjp.v8.2.1725 :

Posted: Fri Aug 10, 2018 6:01 am
by d0wnvk@gmail.com
+1 tricky one..

Re: About Question enthuware.ocpjp.v8.2.1725 :

Posted: Fri May 24, 2019 5:23 am
by tugrulkarakaya
very tricky. shit...