subtyping with wildcards

Rafkind, Jon jon.rafkind at hp.com
Mon Jan 6 15:32:40 PST 2014


Given this code

public class GetClass{
    public void test(){
        foo(getClass());
    }

    public <T extends GetClass> void foo(Class<T> c){
    }
}

I can't get the type inference constraints to reduce to true.

substitute a1 for T

1. getClass() -> Class<a1>
2. Class<? extends GetClass> -> Class<a1>
3. Class<? extends GetClass> <: Class<a1>
A1 = a1, B1 = ? extends GetClass
4. ? extends GetClass <= a1
5. false


I suppose step 2 could have reduced to true if this was true:
  "Otherwise, if T is a parameterized type of the form G<T1, ..., Tn>, and there exists no type of the form G<...> that is a supertype (4.10) of S, but the raw type G is a supertype of S, then the constraint reduces to true."

But it doesn't seem like the middle clause fits:
  "and there exists no type of the form G<...> that is a supertype (4.10) of S"

because where G = Class, there is a form of G that is a supertype of S, namely Class<?>.

Or, step 4 could have reduced to '? extends GetClass = a1' if '? extends GetClass' was a type, but I don't think thats true.
Or lastly, maybe step 4 should reduce to something else assuming the case 'If T is a type, If S is a wildcard, the constraint reduces to false.' was different.



More information about the lambda-spec-observers mailing list