如何访问泛型类型中的泛型类型?
How can a generic type within a generic type be accessed?
假设我有一个摘要class A
public abstract class A<T extends SomeClass, R extends SomeClass> {
...
}
我还有一个class B
public class B<S extends A> {
...
}
如何在 B 中访问 T 和 R?
当我尝试
public class B<F,G,S extends A<F,G>> {
它给出错误
error: type argument K#1 is not within bounds of type-variable K#2
public class B<F,G,S extends A<F,G>> {
^
where K#1,K#2 are type-variables:
K#1 extends Object declared in class B
K#2 extends SomeClass declared in class A
只要@JohannesKuhn 不post他的评论作为答案:
解决方案是class B<T extends SomeClass, R extends SomeClass, S extends A<T, R>>
假设我有一个摘要class A
public abstract class A<T extends SomeClass, R extends SomeClass> {
...
}
我还有一个class B
public class B<S extends A> {
...
}
如何在 B 中访问 T 和 R? 当我尝试
public class B<F,G,S extends A<F,G>> {
它给出错误
error: type argument K#1 is not within bounds of type-variable K#2
public class B<F,G,S extends A<F,G>> {
^
where K#1,K#2 are type-variables:
K#1 extends Object declared in class B
K#2 extends SomeClass declared in class A
只要@JohannesKuhn 不post他的评论作为答案:
解决方案是class B<T extends SomeClass, R extends SomeClass, S extends A<T, R>>