Upper bounds, lower and upper bounds, and multiple bounds with wildcards
843793Dec 7 2003 — edited Dec 8 20031. Upper bounds:
class bound{}
class C<T super bound>{}
Why is this not a valid class declaration, as in contrast to class C<T extends bound>{}. It can be argued that such a declaration is not very useful except in declarations with wildcards (like below), but I can argue the validity of such an argument...
2. Can one make the wildcard type have both lower and upper bounds at the same time? I couldn't figure how to do that, yet I understood the specification as if it should be possible.
3. Multiple bounds within a wildcard:
Having
interface I{}
interface J{}
class C<T>{}
class D{
static <U extends I> void d(C<U>p){}
static void e(C<? extends I>p){}
}
Are methods d and e in class D equivalent?
If so, why then doesn't this compile:
class D{
static <U extends I&J> void d(C<U>p){}
static void e(C<? extends I&J>p){}
}
The compiler complains about expecting > instead of & in declaration of e.
4. Multiple bounds containing wildcards:
Having this valid code at hand
interface I<T>{T i();}
interface J<U>{U j();}
class C<V extends I<V> & J<V>>{}
class D<V extends I<? super V>>{} //or ? extends V
It should be possible to declare:
interface I<T>{T i();}
interface J<U>{U j();}
class C<V extends I<? super V> & J<? super V>>{} //or ? extends V
But the compiler seems to fail here:
"null [9:1] types I<? super V> and I<? super V> are incompatible; both define i(), but with different return type"
[a 22-line-long exception trace of NullPointerException]
The "null" seems to be where the filename should be, and the null exception and its trace where the code and the caret indicating error position should be. The same thing happens when either of the ? super V is removed (except when both removed, that works of course).
Now, that the error-message is bogus and that there is a bug in the compiler is obvious - so my question is: is this a "supposedly" valid syntax, or is it something generally invalid? It should be valid according to my understanding of the issue.
I haven't read the whole forum to see if the issues have been answered, sorry if they have.
-- Irfy