Sorry, maybe it is a silly question, but I can't find answer.
Two generics parameters on a method, could one extends another?
public class A {
}
public class B extends A {
}
public class C {
}
public class Foo {
public static <R extends A> void f1 (A t, R r){
}
// T and R are generics parameter, R bounds on T
public static <T, R extends T > void f2(T t, R r) {
}
public static void main(String[] args) {
A a = new A();
B b = new B();
C c = new C();
Foo.f1(a, b); // no error
Foo.f1(a, c); // compile error, it's ok
Foo.f2(a, b); // no error
Foo.f2(a, c); // no error ! why?
}
}
The last f2
method call has no compile error, but I think C
is not subclass of A
, compile error should be arised. Any help?