Posted by: Naveen Kapoor on: November 21, 2008
public class X{
public static void main(String [] arg){
Set s=new TreeSet();
s.add(new Person(20));
s.add(new Person(10));
System.out.println(s);
}
}
class Person{
int i;
Person(int i){
i = this.i;
}
}
Can anyone tell me why this code fragment shows me the “ClassCastException”, Using Java 2 1.5 compiler.
In the above code
Set s=new TreeSet();
Set S which is a TreeSet accepts an object [...]