subtyping with wildcards
Dan Smith
daniel.smith at oracle.com
Tue Jan 14 10:46:01 PST 2014
On Jan 6, 2014, at 4:32 PM, Rafkind, Jon <jon.rafkind at hp.com> wrote:
> 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>
Here's where you get off track -- you need to apply capture to get to step 2.
Part G, 18.2.1: "if the expression is a standalone expression (15.2) of type S, the constraint reduces to ⟨S → T⟩."
The type of 'getClass' is Class<X> where X extends GetClass -- see Part F, 15.12.2.6: "The type of the method invocation expression is obtained by applying capture conversion (5.1.10) to the return type of the invocation type of the chosen method."
—Dan
> 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