Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4901682
Votes 0
Synopsis spec for type inference versus implementation (array covariance)
Category java:specification
Reported Against tiger
Release Fixed 1.5(tiger-rc)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 06-AUG-2003
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.
Work Around
N/A
Evaluation
The up to date makes it clear when the bounds are used in the inference
process. Usually they are not.

  xxxxx@xxxxx   2004-06-04
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang