Java Method-Local Inner Classes are Unsound
summary
Claim: Java’s combination of method-local inner classes plus erased generics and class-based visibility lets a non-generic local class implicitly tied to a method type parameter escape one invocation and be reused under a different instantiation, producing a value typed as Foo<String> that actually contains an Integer and later throws ClassCastException. JVM erasure makes instanceof and casts succeed (no compiler warnings), raw types and overload-driven checkcasts mask the error, and languages like Scala/Kotlin mitigate it by warning or rejecting such checks.
AI-written summary · about
chapters (9)
- 0:00Method-local inner classes
- 1:47What is a method-local inner class
- 3:13Java generics interaction
- 4:20Unsoundness example
- 11:06Simpler unsoundness example
- 12:08JVM bytecode analysis
- 14:54Other JVM languages
- 18:22Core issue and solutions
- 20:07Q&A
related talks
38mThe Sincerest Form of Flattery
21mWat? That’s Possible in Java?
49mType Specialization of Java Generics - What If Casts Have Teeth ?
51mThe Sincerest Form of Flattery
01h 00mJava Language Futures - All Aboard Project Amber
55mLocal Variable Type Inference: Friend or Foe?
58mJava Sucks (So C# Didn't Have To)
23mThe Java Features You’re Missing Out On
