1
申し訳ありません、多分それは愚かな質問ですが、私は答えを見つけることができません。Genericsパラメータは、Javaメソッドの別のパラメータを拡張します
メソッドの2つのジェネリックパラメータは、1つを別のものに拡張できますか?
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?
}
}
最後f2
メソッドの呼び出しには、コンパイルエラーを持っていませんが、私はC
は、エラーがarisedれるべきコンパイルA
のサブクラスではないと思います。どんな助け?
なぜ 'T'は' A'だと思いますか? – user2357112