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

4.3: Clarify status of unnamed types

XMLWordPrintable

      Capture variables, intersection types, and the null type are "unnamed", meaning they cannot be referenced syntactically; but they are still types. JLS 4.1 and 4.3 do not mention them in the grammar rules. Of course, we cannot simply add them to the grammar rules, because then they would be valid syntax. Instead, we need a concept of "reference type" that is broader than just the set of valid syntax, ReferenceType.

      Intersection types are the simplest case: clearly, they are reference types. But they are not mentioned at all in section 4.3.

      Capture variables are "just" type variables, per 5.1.10, but they have unique properties that go unmentioned in 4.4 (no declaration, unclear scope, a lower bound). So they should either be defined as unique entities, or 4.4 should be general enough to describe them as well.

      The status of the null type is vague. 4 (intro) and 4.1 can be read to treat is as a third kind of type (in addition to primitive and reference) or as a kind of reference type. It makes the most sense to treat it as a reference type, since all values are either primitives or references, and "null type" describes a subset of references. In that case, it should be described as an unnamed reference type in 4.3.

      Also note that intersection types and capture variables can appear as part of a class type, interface type, or array type, due to substitution. So types like 'List<Foo & Bar>' are _also_ unnamed types. Some class types are not ClassTypes; some interface types are not InterfaceTypes; some array types are not ArrayTypes.

      (The null type can never appear as part of another type, because of how it is treated by type inference.)

            dlsmith Dan Smith
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: