Nidhi Sar wrote:
e.g. If the Set is defined as a TreeSet<String>, how can a Comparator<Object> be used to sort it?
Agreed. In your example, it is not that useful, as there isn't really any way to sort the Object class.
But what about a different setup... Say you have Object --> Vehicle --> Car --> SUV --> Escalade. And you have a treeset of Escalade, that you just want sorted as a Car, as that is good enough for you. All Escalade are Cars, so why can't you sort it like a car, if you wanted to?