如何将泛型类扩展为泛型 [英] How to extend generic class to be also generic

查看:77
本文介绍了如何将泛型类扩展为泛型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在上这堂课: 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆