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

6.5.5.1: Clarify the simple name of a generic inner class type

    Details

      Description

      What is the type referred to by a generic inner class name, where that class is a member of another generic class?

      class Outer<T> {
        class Inner<U> {
          T get() { return null; }
        }

        void test() {
          // some examples:
          Inner i = new Inner(); // javac treats as a raw type
          T t = new Inner().get(); // javac type error
          Inner<String> i = new Inner<>(); // javac allows
        }
      }

      If the meaning of "Inner" in this context is the class "Outer<T>.Inner", then these uses are attempts "to use a type member of a parameterized type as a raw type", and so are errors (4.8).

      If the meaning of "Inner" in this context is the class "Outer.Inner", then certain type errors or unchecked warnings may be required.

      javac seems to prefer the latter. It seems cleaner to me to prefer the former. In either case, this should be clarified in, e.g., 4.3/4.8.

      But note that a TypeDeclSpecifier, as used by 4.3 and 15.9, retains the "Outer<T>.Inner" meaning -- it is only when the "Inner" syntax is interpreted as a full type, and turns out to have no type arguments, that the qualifying type is erased (or, if the first interpretation is preferred, a "rare type" error occurs).

        Attachments

          Activity

            People

            • Assignee:
              dlsmith Dan Smith
              Reporter:
              dlsmith Dan Smith
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: