There is a difference between the challenges.
In a query that compiles,
instGrA.testExtends(instGrB);
are you passing Group<BClass<String>> method waiting for Group<? extends AClass<?>> Group<? extends AClass<?>> . This is appropriate because BClass<String> is a subtype of AClass<?>> - BClass is a subclass of AClass and String is a subtype ? .
However, in a call that does not compile,
instGrB.testSuper(instGrA);
are you passing Group<AClass<String>> method waiting for Group<? super BClass<?>> Group<? super BClass<?>> . This is not appropriate because, although AClass is a superclass of BClass , AClass<String> not a supertype of BClass<?> .
The wildcards inside the testExtends and testSuper parameters testExtends testSuper . Since you assign AClass and BClass to T in your instances, you can use them. I can get this to compile if we change the declarations of these methods in Group to use T :
public void testExtends(Group<? extends T> value){} public void testSuper(Group<? super T> value){}
source share