The Unsound Playground: Java and Scala's Type Systems are Unsound
The headline is misleading as the type system is sound, but the general idea of generics is that the type bindings and constraints should result in a guarantee that there won&#x27;t be any failing casts at runtime. And they&#x27;re interpreting the failure to catch all detectable errors statically as a sign of unsoundness, which is not a correct assertion.<p>The Java language&#x27;s half-assed generics implementation works by type erasure - so everything is boxed to Object. Because of that erasure my guess is that they&#x27;re not handling inner class type binding correctly (maybe they&#x27;re not able to? I don&#x27;t know their compiler internals - fundamentally it _should_ be possible). If anything i&#x27;d argue that this is a compiler bug.<p>Anyway, the end result is a type safe (and entirely sound) runtime and language -- if it were not sound it would be possible to write code that _should_ trigger a type failure, either at compile or at runtime, but that doesn&#x27;t. That is what it means to have an unsound type system, for example all C-derived languages have unsound type systems. Remember the Java has no guarantees of full static safety (the ability to downcast Object to anything ensures that they can never be fully statically typed), so as long as you&#x27;re guaranteed the the runtime will never let an invalid cast or conversion happen its still correct. Another way of triggering this would be to use introspection to instantiate an instance of a generic class. Because the VM is unaware of generics you&#x27;ll just get an Object interface through which you could trigger the same faults.<p>Footnote: .NET actually gets generics right, it&#x27;s not done through erasure but actual correct type bindings. The VM is itself aware of parametric types and instances of said types and so can statically verify the IL itself, so even if you make an unsafe language that targets .NET the VM would reject illformed&#x2F;unsound IL, before running it: this is VM equivalent of a static failure: it&#x27;s not waiting for a dynamic cast to fail at runtime.