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

4.9: Intersection type with unbounded wildcard legal?

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u5
    • specification

      FULL PRODUCT VERSION :
      java version "1.8.0_05"
      Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.3.9600]

      A DESCRIPTION OF THE PROBLEM :
      As far as I can tell the enclosed program is illegal according to the spec. Here's why. The members of the type T are the members of the intersection type Object&A<?> (JLS 4.4). Those are the members of a class that is written to implement Object and A<?> (JLS 4.9). But such a class is illegal because "none of the type arguments may be wildcard type arguments" (JLS 8.1.5). Therefore the extends clause in the actual program must be illegal.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the enclosed program; observe that its acceptance is in conflict of the requirements of the language specification.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The specification allows the attached program and defines its semantics.
      ACTUAL -
      The specification disallows the attached program.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Main {
          public static void main(String[] args) {
          }
      }

      interface A<T> {
          T f();
      }
      class C {
          <T extends Object & A<?>> void f(T t)
          {
              Object o = t.f();
          }
      }

      ---------- END SOURCE ----------

            dlsmith Dan Smith
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: