I have a class which has a self referential generic parameter and a parameter which is of the same super class. The static function has identical bounds as the class.
public class Bar<T extends Bar<T, C>, C extends Bar<C, ?>> {
Bar() {
foo((T) null);
foo((C) null);//compile error
}
static <S_T extends Bar<S_T, S_C>, S_C extends Bar<S_C, ?>> void foo(S_T t) {
}
}
This gives the following error.
Bound mismatch: The generic method foo(S_T) of type Bar<T,C> is not applicable for the arguments (C). The inferred type C is not a valid substitute for the bounded parameter <S_T extends Bar<S_T,S_C>>
I can't figure out why C
can't be passed in to foo()
since C
is Bar<C,?>
and the wildcard is a Bar
because of the second parameter in the declaration says it extends Bar.
I know this is probably a bad idea and produces code which is hard to understand but I really wanna know why this doesn't compile.