Aug
29
2007
Todays Java Atrocity
{
{
// Use klass to overcome Java generics limitations
}
}
{
{
// Cannot convert from Class<List> to Class<List<Integer>>: fair enough
Class<List<Integer>> klass1 = List.class;
// Integer and List cannot be resolved: huh, that's an odd error
Class<List<Integer>> klass2 = List<Integer>.class;
// Cannot cast from Class<List> to Class<List<Integer>>: they should be equivalent after erasure, but fine
Class<List<Integer>> klass3 = (Class<List<Integer>>)List.class;
// This works! Awesome! But it's dead ugly (and unchecked of course), and why should I have to cast
// to Class<?> before what I want? This means the castable-to relationship is >not transitive<!
Class<List<Integer>> klass4 = (Class<List<Integer>>)(Class<?>)List.class;
}
}