What is going on here?
The list will not be printed, only the object references. Or should we assume there is a toString()?
About Question enthuware.ocpjp.v11.2.1862 :
Moderator: admin
-
- Posts: 1
- Joined: Wed Feb 02, 2022 6:58 pm
- Contact:
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.1862 :
There is no need to assume. All objects have a toString method already. It may not print the value of the fields of the object, but it does print a unique string for that object (No, it doesn't print object reference. It prints the hashcode).
Further, what the code actually prints is not really relevant here because all it says is that the list is printed, which it does. It doesn't claim anything about the actual format or content of what is printed.
Further, what the code actually prints is not really relevant here because all it says is that the list is printed, which it does. It doesn't claim anything about the actual format or content of what is printed.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Thu Aug 04, 2022 10:23 am
- Contact:
Re: About Question enthuware.ocpjp.v11.2.1862 :
The book class is not implementing Comparable interface then how the compareTo function is working on line //1
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.1862 :
Book doesn't implement Comparable. But the code passes a Comparator instance that is able to compare two Book objects.
This Comparator uses the compareTo method of String class.
Observe the lambda used to create the Comparator. It calls b1.getGenre().compareTo and not b1.compareTo.
This Comparator uses the compareTo method of String class.
Observe the lambda used to create the Comparator. It calls b1.getGenre().compareTo and not b1.compareTo.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Thu Aug 04, 2022 10:23 am
- Contact:
Re: About Question enthuware.ocpjp.v11.2.1862 :
Thanks for the explaination. Got it.
Who is online
Users browsing this forum: No registered users and 102 guests