Page 1 of 1

About Question enthuware.ocpjp.ii.v11.2.1477 :

Posted: Tue Jan 05, 2021 6:19 pm
by philippe
You have a collection which contains objects of a class X. When the collection is sorted using Collections.sort(collectionOfX);, X's compareTo() method is used. Which of the following statements are correct about this class X?
Regarding the second correct answer:
The mechanism used in this situation allows the Objects of class X to be sorted in only one way (and the reverse of that way).
How can the list be sorted in the reverse way without using a Comparator?

Re: About Question enthuware.ocpjp.ii.v11.2.1477 :

Posted: Tue Jan 05, 2021 9:55 pm
by admin
Not using without a Comparator but without using any new logic that is not already embedded in the compareTo.

The option says, "The mechanism used in this situation allows the Objects of class X to be sorted in only one way (and the reverse of that way)." and this is true because you can do this:

Collections.sort(list, Collections.reverseOrder());