sharma ishu wrote:
This code allows you to use instances of Stuff as keys in Maps or not? And why?
Why it will not allowed to use instance of Stuff as key ?
In any map you can use Stuff as a key, no compilation error.
But in TreeMap , you can't use Stuff object as a key, because in TreeMap the key should be implement comparable interface not comparator, so in TreeMap it gives run-time error...
sharma ishu wrote:
.... problem is from "Practice Exam by Kethy and Bert" 2011. Page 204-Ques.22.
The question you spotted is about sorting, so NameCompare comparator sort the collection in descending order as "return b.name.compareTo(a.name); ".
Hope that will help you.
Thanks,
Ankit