The reason for compiler warnings is Comparator interface is a parameterized one. And in your code, you are not passing any type parameter while implementing. Please have a look at the Java API for more info about Comparator interface!
The above code doesn't compile! Because Object class doesnt implement Comparator interface and doesnt have a method compareTo(), ob1.compareTo(ob2) will give compiler error!
Hope this is clear! [ December 01, 2008: Message edited by: M Srilatha ]
Changing your code to something like this.. will not throw any warnings..
You say that TreeSet takes in a Generic type of class A . But when implementig comparator interface on class A you should also pass on the generic type on it.. check out the api doc for java.util.Comparator Interface for further reference..
So in the code above implemented abstract method takes the generic type as parameters and throws no compiler warnings. [ December 01, 2008: Message edited by: Vipun Reddy ]
Joined: Sep 07, 2008
Hi Vipun, I tried your code it gives warning. anyway i will go through documentation. warning on...Set<A> cs=new TreeSet<A>(new A());//unchecked conversion.