3 ms·
> It returns a ClassCastException because underneath it all, in the Java bytecode the Java compiler stores generics as casts. Right - the article already says
by chrisseaton 10y ago
> It returns a ClassCastException because underneath it all, in the Java bytecode the Java compiler stores generics as casts.
Right - the article already says that doesn't it?
> If they had baked generics in at the beginning of Java then it wouldn't have compiled
Why wouldn't it have compiled if the JVM had generics? It's an error in the design of the type system of the language isn't it? The type system is the same if we have reified generics or erased generics isn't it? And that's where the failure is - not at the JVM level.
- _old_dude_ 10y agoI agree with Chris, it would be a lot worse if generics were reified in Java because instead of having some spurious ClassCastExceptions, you will get memory corruptions instead.