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

Failure to detect malformed parameterized type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 7u51, 8u60, 9
    • tools

      The following program compiles without error. An error is expected.

      public class Test {
          interface I<T extends Class<S>, S> {}
          
          <T extends Class<?>> void test() {
              I<T,?> val;
          }
      }

      Specifically, the type 'I<T,?>' is malformed, and so should produce an error (JLS 4.5).

      "When subjected to capture conversion"
      --> 'I<T,CAP>'
      "each type argument Xi is a subtype of" its bound
      --> T <: Class<CAP>

      Because T has upper bound Class<?>, it is not a subtype of Class<CAP> -- in fact, there exists no type Foo such that T <: Class<Foo>.

      (Some aspects of type variables with wildcard-parameterized bounds are under-specified, but in this case, the definition of subtyping is clear.)

      This appears to be longstanding behavior, probably since Java SE 5.

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

              Created:
              Updated: