Using the JSR14 compiler I'm getting a crash that seems non-intuitive to me as to the cause. I've written a segment of code that simulates the same effect:
public class MapTest{
public static void main( String[] args ){
Set<Outer> oset = new TreeSet<Outer>();
for( int i = 0; i < 5; ++i ){
System.out.println( i );
Inner j = new Inner();
oset.add( j );
}
}
}
class Outer{ public int x; }
class Inner extends Outer{ public int y; }
which crashes when inserting the second element with a ClassCastException:
Exception in thread "main" java.lang.ClassCastException
at java.util.TreeMap.compare(TreeMap.java:1081)
at java.util.TreeMap.put(TreeMap.java:459)
at java.util.TreeSet.add(TreeSet.java:205)
at MapTest.main(MapTest.java:15)
Is this supposed to happen? Any help is appreciated.