United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4901682 : spec for type inference versus implementation (array covariance)

Details
Type:
Bug
Submit Date:
2003-08-06
Status:
Resolved
Updated Date:
2004-06-04
Project Name:
JDK
Resolved Date:
2004-06-04
Component:
specification
OS:
solaris_8
Sub-Component:
language
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
5.0 (rc)

Related Reports

Sub Tasks

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


                                     
2004-06-14
EVALUATION

The up to date makes it clear when the bounds are used in the inference
process. Usually they are not.

###@###.### 2004-06-04
                                     
2004-06-04



Hardware and Software, Engineered to Work Together