JDK-4901682 : spec for type inference versus implementation (array covariance)
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2003-08-06
  • Updated: 2004-06-04
  • Resolved: 2004-06-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 rcFixed
Description
The spec requires that the inferred type arguments are within bounds. See section 5.6.2. It talks of type parameters T extends U1&...Um, for which a type argument A is inferred, which is "the most specific non-null type such that ... T:=A". Which means that the inferred type argument must in within bounds. That's not what the compiler does.

Example:

public class Cell2 {
    
   <A, B extends A> doS(A[] h, B i)  {
   	h[0] = i;   	
   }   
   
   public static void main(String[] args) {   
      Cell2 c = new Cell2();
      c.doS(new Integer[]{new Integer(5)}, new String("Hallo"));      
   }
}

yields the error message:

Test.java:8: doS<A, B extends A>(A[],B) in Test cannot be applied to 
(java.lang.Integer[],java.lang.String); inferred type argument(s)
java.lang.Integer,java.lang.String do not conform to bounds of type
variable(s) A,B
        doS(new Integer[] {new Integer(5)}, "hello");
        ^
1 error

Why does the compiler infer A:=Integer and B:=String? According to the spec it must infer A:=Object and B:=Object, because they conform to the bounds.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: tiger-rc INTEGRATED IN: tiger-rc
14-06-2004

EVALUATION The up to date makes it clear when the bounds are used in the inference process. Usually they are not. ###@###.### 2004-06-04
04-06-2004