Sebastiaan van Erk wrote:
ARgh, you always make typos with this stuff.
See correction.
Sebastiaan van Erk wrote:
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
(correction:)
Foo<? extends Bar<?>> rawbar = new Foo<RawBar>(); // DOES NOT WORK
- THIS IS CAUSING ONE HALF OF ALL OUR HEADACHES
Btw, this does work (like you expect):
Foo<? extends Bar<?>> rawbar2 = new Foo<SubBar<?>>();
maybe some more wisdom can be found here:
http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ209
In her words it would mean 'raw types are not part of the type family
denoted by the wildcard parametrized type Bar<?>'
But I'm still puzzled, since taking that FAQ it doesn't explain why in
the case of the generic method
public <T extends Component<?>> void dol(Class<T> clazz)
the raw types are all of a sudden member of that family
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).
the faq comes up with this:
http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html#FAQ106
and this:
http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html#FAQ310
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
Happy Weekend,
Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]