JDK-8046690 : 4.9: Intersection type with unbounded wildcard legal?
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 8u5
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2014-06-10
  • Updated: 2014-06-20
  • Resolved: 2014-06-20
Related Reports
Duplicate :  
Description
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 ----------