Creating array using type variable as element type

Issue #108 resolved
Jesper Öqvist created an issue

It should not be allowed to create a new array with a type variable element type, for example:

public class Test<T extends Integer> {
        T[] array = new T[10];// error: not valid array element type

This error is specified in JLS SE7 $15.10:

It is a compile-time error if the ClassOrInterfaceType does not denote a reifiable type ($4.7).

Comments (3)

  1. Jesper Öqvist reporter

    We don't have an attribute for checking if a type is reifiable. An isReifiable attribute would be useful.

  2. Jesper Öqvist reporter

    An isReifiable attribute already existed, but it was in the Java 7 extension. It should be moved to the Java 5 extension so that it can be used for array creation type checking.

  3. Jesper Öqvist reporter

    Type check generic array creation

    Disallow creating arrays with non-reifiable element type.

    Moved TypeDecl.isReifiable from Java 7 extension to Java 5 extension.

    fixes #108 (bitbucket)

    → <<cset 3a0d0fa66387>>

  4. Log in to comment