Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4959929

unclear diagnostic for "new T()"

XMLWordPrintable

    • b40
    • generic
    • solaris_8

      Date: Tue, 25 Nov 2003 09:49:32 -0800
      From: <###@###.###>
      Subject: Suggestion: better error message for "new T()"
      To: <###@###.###>

      I can understand why type erasure does not allow

      new T()

      but users might be scratching their heads.

          private static class Type<T> {
      Type() { T t = new T(); }
          }

      gives

      NewT.java:4: unexpected type
      found : T
      required: class
      Type() { T t = new T(); }
                                 ^

      It would be nice if we could give an error message like we do with
      arrays,

      arrays of generic types are not allowed

      making it clear(er) why "new T()" is not allowed.

            never Tom Rodriguez
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: