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

4.11: Type contexts do not include wildcard type arguments

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 24
    • specification

      Section 4.11 does not consider a wildcard type argument which has a bound to be the use of a type.

      In such a wildcard type argument, the bound is_ considered to be the use of a type:

      > A non-wildcard type argument, or a bound of a wildcard type argument, of a parameterized type in any of the above contexts.

      And, a wildcard type argument which is unbounded -- `?` -- is considered to be the use of a type:

      > An unbounded wildcard (§4.5.1)

      But the wildcard type argument `? extends ...` as a whole is not considered to be the use of a type.

      This has an implication for annotation interfaces applicable to type contexts (JLS 9.7.4). Given 4.11, for the wildcard type argument `@TA ? extends @TB Number`, the annotation `@TA` does not apply to the use of a type, hence does not appear in a type context, hence is not a type annotation (even though it is plainly meant to be a type annotation). The annotation `@TB` has no such troubles: it applies to the use of a type (the bound of a wildcard type argument), hence appears in a type context, hence is a type annotation.

      However, I am not sure what is the most appropriate fix for this issue. Type arguments are still not types, and if we consider use of wildcard type arguments as use of types, this may bring unintended implications. I personally suggest investigating the use of 4.11 before changing it, or simply adjusting 9.7.4 to add wildcard type arguments to the applicable targets of type-use annotations.

            Unassigned Unassigned
            liach Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: