1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817
- Posts: 1
- Joined: Sun May 28, 2017 4:22 am
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).admin wrote:Why do you think so?
- Site Admin
- Posts: 9170
- Joined: Fri Sep 10, 2010 9:26 pm
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.
Users browsing this forum: Bing [Bot] and 3 guests