Forum Stats

  • 3,855,563 Users
  • 2,264,523 Discussions


What Comparators are defaulted?

843793 Member Posts: 41,732 Green Ribbon
edited Apr 4, 2003 10:18PM in Generics
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.put(
at java.util.TreeSet.add(
at MapTest.main(

Is this supposed to happen? Any help is appreciated.


This discussion has been closed.