unchecked conversion with self-referencing type parameter

Rafkind, Jon jon.rafkind at hp.com
Thu Jan 30 12:19:06 PST 2014


In the following code javac warns that unchecked conversion was needed,
but my own type inference engine doesn't find a case where unchecked
conversion is possible.

public class C<X>{
    public <T extends C<T>> void foo(Class<T> c){
    }  
   
    public void test(){
        Class<C> c = null;
        foo(c);
        // foo(C.class); // originally my test case was this, but its
the same as using 'c'
    }  
}

Substitute 'a1' for T.

Bounds: a1 <: C<a1>
Constraints: c -> Class<a1>

reduce 'c -> Class<a1>'
1. c -> Class<a1>
2. Class<C> -> Class<a1>
// at this point I think unchecked conversion is needed as loose
constraints are the only place in the reduction process that mention
unchecked conversion
// but case 1 doesn't apply (Class<a1> is not proper), and case 4
doesn't apply because G = Class<a1>, S is already a form of G = Class<C>.
3. Class<C> <: Class<a1>
4. C <= a1
5. C = a1

add bound C = a1, infer the constraint 'C <: C<a1>' during incorporation.

reduce 'C <: C<a1>'
1. C <: C<a1>
fail, because C<a1> is a parameterized type but there is no super type
of C that is a parameterized type of C


More information about the lambda-spec-observers mailing list