Have I missed something with <? super T>

Hiya, I tried searching for this, but it's so difficult to figure what the subject is. Anyway the following fails to compile on 1.6 U1 and I can't figure out why?

interface Foo<T> {

}

interface FooListener<T> {

void fooArrived(Foo<T> theFoo);

}

class FooListenerWrapper<T>

implements FooListener<T> {

FooListener<? super T> myListener;

FooListenerWrapper(FooListener<? super T> theListener) {

this.myListener = theListener;

}

public void fooArrived(Foo<T> theFoo) {

this.myListener.fooArrived(theFoo);

}

}

Gives:

fooArrived(Foo<capture#48 of ? super T>) in FooListener<capture#48 of ? super T> cannot be applied to (Foo<T>)

this.myListener.fooArrived(theFoo);

I assume that "? super T" means that it will take anything of T or of a super type, yet this is disallowed?

Any help would be appreciated.

Bob.

[1004 byte] By [Phuckstera] at [2007-11-27 5:55:11]
# 1

That is because, for example, Foo<Number> is not a supertype of Foo<Integer>. Hence, if you have a FooListener<Number>, it can take Foo<Number>, but no Foo<Integer> according to your definition of FooListener.

More about supertype/subtype relationships can be found in [url=http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#Which%20super-subtype%20relationships%20exist%20among%20instantiations%20of%20parameterized%20types?]Angelika's FAQs[/url].

stefan.schulza at 2007-7-12 15:50:37 > top of Java-index,Core,Core APIs...
# 2

I looked at that originally, and Angelika's comments contradict yours:

"Number is a supertype of Long , and for this reason the type family " ? super Number " is smaller than the type family " ? super Long "; the latter includes type Long as member, while the former excludes it."

And it is exactly the result of your example that I am trying to achieve, to allow "super" listeners to be added to extended types.

But, having said that, your comment about my *definition* is correct, my definitions should be have been:

interface FooListener<T> {

void fooArrived(Foo<? extends T> theFoo);

}

To allow Integers (extended types of Number) to be passed to the number listeners.

Thanks for the pointer.

Bob.

Phuckstera at 2007-7-12 15:50:37 > top of Java-index,Core,Core APIs...
# 3

No, it doesn't contradict my statement. I didn't talk about wildcards but your use of Foo<T>. Of course, if you have a type family as parameter this is different and has nothing to do with super- and subtypes wrt. the outer type. The question is, whether using an upper bound wildcard, as your new definition does, serves the information necessary to handle the instances.

stefan.schulza at 2007-7-12 15:50:37 > top of Java-index,Core,Core APIs...