Re:The Unsound Playground: Java and Scala's Type Systems are...
by olliej on Sunday November 27, 2016 @03:09PM
(#13051190)
Do you have a spec reference for that (not trying to be a dick - i just want to understand what the type system believes it should be doing here as the value being assigned to a reference should not influence the type system behaviour)
[ Parent
| on HN ]
Re:The Unsound Playground: Java and Scala's Type Systems are...
by jhdevos on Sunday November 27, 2016 @03:28PM
(#13051318)
This is explained in the article in a bit more detail. The point is not that the type system does something with the actual value - the point is that it would be impossible to create any code that results in such a value (other than null), since then you would have to provide an actual type that is somewhere between Integer and String - and that would obviously not pass the type checking. Using null avoids that.
Section 4.5 in the language spec deals with parameterized types; 4.5.1 deals with wildcards. Of course, there is no example in the specs that clearly points out what happens in this example - otherwise this wouldn't have remained undiscovered for so many years :)
If you can show, using the rules in the spec, that the sample program shouldn't pass type checking, then you'll have proved the article wrong :-)