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

unclear diagnostic for "new T()"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 5.0
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b40
    • CPU:
      generic
    • OS:
      solaris_8

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            never Tom Rodriguez
            Reporter:
            gafter Neal Gafter
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: