如何将泛型类扩展为泛型 [英] How to extend generic class to be also generic
问题描述
我正在上这堂课:
public class My class <T extends Serializable>
我想将其扩展到新的泛型类
public class Class2<T> extends My class<T>
I am having this class :
public class My class <T extends Serializable>
I want to extend it to a new generic class
public class Class2<T> extends My class<T>
给出绑定不匹配错误 尽管几年前我获得了Java see证书,但我现在实际上实际上并不记得这些规则,也无法访问该材料:(
It gives bound mismatch error I don't remember the rules now actually and has no access to the material though I got the java see certificate few years ago :(
推荐答案
子类Class2
的类型参数T
必须满足超类Myclass
的类型限制:
The type parameter T
of your sub-class Class2
must satisfy the type bound of the super class Myclass
:
public class Class2<T extends Serializable> extends Myclass<T>
否则,T
不能用作Myclass
的通用类型参数.
Otherwise T
cannot be used as the generic type parameter of Myclass
.
这篇关于如何将泛型类扩展为泛型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!