List to TreeSet conversion produces: "java.lang.ClassCastException: MyClass cannot be cast to java.l
        Posted  
        
            by Chuck
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Chuck
        
        
        
        Published on 2010-03-24T01:32:46Z
        Indexed on 
            2010/03/24
            1:43 UTC
        
        
        Read the original article
        Hit count: 586
        
java
|classcastexception
List<MyClass> myclassList = (List<MyClass>) rs.get();
TreeSet<MyClass> myclassSet = new TreeSet<MyClass>(myclassList);
I don't understand why this code generates this:
java.lang.ClassCastException: MyClass cannot be cast to java.lang.Comparable
MyClass does not implement Comparable. I just want to use a Set to filter the unique elements of the List since my List contains unncessary duplicates.
© Stack Overflow or respective owner