Search code examples
javagenericsjls

Where in the JLS is the explanation for it to be legal the assignment of a raw type to an unbounded type?


I'm looking for a JLS quote for the following sentence to be legal:

Vector<?> vector = PreJava5API.getRawVector();

Solution

  • You can start from the section about assignment

    https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.26.1

    which allows assignment conversion

    https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.2

    which allows unchecked conversion

    https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.9

    which allows conversion from raw G to G<?>, without a warning.