java—如何访问泛型类型中的泛型类型?

0mkxixxg  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(432)

假设我有一个抽象的a级

public abstract class A<T extends SomeClass, R extends SomeClass> {
...
}

我还有一个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
xvw2m8pv

xvw2m8pv1#

只要@johanneskuhn不发表他的评论作为答案:
解决办法是 class B<T extends SomeClass, R extends SomeClass, S extends A<T, R>>

相关问题