Sebastiaan van Erk <[EMAIL PROTECTED]> writes:
>
> Ismael Juma wrote:
> > Sebastiaan van Erk <[EMAIL PROTECTED]> writes:
[...]
> > Once you add a type parameter to E, it either doesn't apply anymore or the
> > compilers are buggy. More specifically, these two are not the same
> > according to the eclipse compiler and javac:
> >
> > - public final <C extends Page<?>> void setResponsePage(final Class<C> cls,
> > PageParameters parameters)
> > - public final void setResponsePage(final Class<? extends Page<?>> cls,
> > PageParameters parameters)
> >
> > The former accepts some class literals that the latter does not.
>
> If two compilers disagree, this would seem to be a bug in at least one
> of them!
You misunderstood. "former" and the "latter" refer to the two lines of code and
not to the two compilers. However, there are indeed some cases where the eclipse
compiler and javac differ, but here I was actually talking about cases where
_both_ would reject a class literal when it was passed to the second line
instead of the first.
[general explanation regarding how generics work snipped]
> When you use a type bound, you do not have this problem:
>
> 1) public Object method(Foo<? extends Bar<?>> y)
>
> You cannot call method((Foo<SubBar<T>>) y) because SubBar<T> is not a
> subtype of ? extends Bar<?> for the above reasons.
>
> 2) public <S extends Bar<?>> Object method(Foo<S> y)
>
> The type parameter is bounded, and now it is allowed to use SubBar<T>
> because the T is captured by the wildcard and the method has signature
> method(Foo<SubBar<T>> y) and thus takes a type *without* wildcards.
[...]
I am probably missing something. The following compiles:
public class Generics {
public static void main(String[] args) {
method1(new Foo<SubBar<?>>());
method2(new Foo<SubBar<?>>());
}
static Object method1(Foo<? extends Bar<?>> y) {
return null;
}
static <S extends Bar<?>> Object method2(Foo<S> y) {
return null;
}
static class SubBar<T> extends Bar<T> {
}
static class Bar<T> {
}
static class Foo<T> {
}
}
Can you clarify which part should be different for me to have the same results
as you?
Regards,
Ismael