3 ms·
No, you can't cause "heap corruption". One of the casts inserted by the javac compiler can fail at runtime though. The JVM does not know or care about generics;
by titzer 5y ago
No, you can't cause "heap corruption". One of the casts inserted by the javac compiler can fail at runtime though. The JVM does not know or care about generics; they are "erased."
- rzwitserloot 5y agoHaving a Dog in a list of Cats is called 'heap corruption' in most places (including the relevant mailing lists on openjdk itself). It doesn't cause core dumps or security issues, it merely means any attempt to meaningfully interact with it will cause a ClassCastException on use. Still called 'heap corruption'. Even if as far as the JVM is concerned, that's just a list of whatevers - it doesn't matter, on-use the bytecode will cast.