Martin Funk wrote:
Class<? extends Page<?>> means "class of (anything that extends (page of anything))".I'm not so sure.
There are 2 separate issues:ISSUE 1: Foo<? extends Bar<?>> is not assignable from a Foo<RawBar> where RawBar extends Bar as a raw type. That is, given:
static class Foo<T> {
}
static class Bar<T> {
}
static class RawBar extends Bar {
}
static class SubBar<T> extends Bar<T> {
}
Thus:
Bar<?> bar = new RawBar(); // works, because RawBar is a subtype of
Bar<?>
But:Foo<? extends Bar<?>> rawbar = new RawBar(); // DOES NOT WORK - THIS IS CAUSING ONE HALF OF ALL OUR HEADACHES
Note that this is the issue that complete baffles me, as RawBar is a subtype of Bar<?>, so I *really* *really* *REALLY* have no idea why the compiler chokes on this.
ISSUE 2: The class literal of a generic type returns a class of a raw type. Thus Foo.class return Class<Foo>. This is also really messed up, because:
Class<Foo> fc = Foo.class;
compiles, but generates a warning (reference to raw type). But if you
type this in eclipse:
x fc = Foo.class;and use eclipse quickfix to change "x" to the "correct" type, it'll change it to precisely Class<Foo> (the JLS is very short about this, see also http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.8.2).
So what the heck is the proper type for the class literal??? I couldn't find any!
Finally, note that when you define a method like this:
static void method1(Foo<? extends Bar<?>> y) {
}
it works like a charm for a new Foo<SubBar<String>>, i.e., the "Foo of
(anything that extends (bar of anything))" really is the correct
interpretation.
It's just that the interaction with raw types is completely *foobar* (pun intended).
Regards, Sebastiaan
smime.p7s
Description: S/MIME Cryptographic Signature
