|
|
|
|
|
by jhdevos
3484 days ago
|
|
I don't see the headline as misleading at all. There are two type systems in Java: the JVM's run-time type system, and Java's compile time type system. It's the latter that has been shown to be unsound. As the paper notes, it's fortunate that generics have been implemented with type erasure, because that is what saves the JVM from being unsound, too. As for the problem itself: it really has nothing to do with inner classes (they are static in the example!). The problem is with this line: Constrain<U,? super T> constrain = null;
which leads the type system to assume that there is a type that is a superclass of T, which also is a subclass of B (from the 'Constrain' class) - even though no such type could possibly exist! The evil trick is in the 'null' - even though a type with the stated constraints is impossible, and so no actual 'real' value of this generic type could exist, 'null' is part of all types, so the compiler can't see the problem.It really is a problem in the type system as defined in the standard, not just a compiler bug. |
|
If we look at concrete execution instance with String and Integer:
String implies Object, Serializable, Comparable<String>, CharSequence. None of those imply/extend Integer, which is required for truthful Constrain<U, ? super T> proposition.
Basically, ex falso quodlibet :)
EDIT: spacing, formatting, wording.