Comparing extended objects
Normally I'm not completely clueless with generics, but this one has me stumped. Consider the following code, which compiles and runs cleanly without generics:
publicclass Fooimplements Comparable{
publicint bar;
publicint getBar(){return bar;}
publicint compareTo(Object obj){
return getBar() - ((Foo)obj).getBar();
}
}
-
publicclass ExtendedFooextends Foo{
publicint blah;
}
-
publicstaticvoid main(String[] args){
ArrayList arr =new ArrayList();
Foo f =new Foo();
f.bar = 0;
arr.add(f);
f =new ExtendedFoo();
f.bar = 1;
arr.add(f);
Collections.sort(arr);
}
But how do you make it compile with generics?

