Java泛型(类型参数T)3――多接口限制

匿名 (未验证) 提交于 2019-12-02 21:53:52

泛型示例三:

public class TPractice<T extends Calendar & SolarTerms & Festival> { // 限制 T类型为继承Calendar 类,并实现SolarTerms、Festival 接口的类类型

















}

class Calendar {




}

interface SolarTerms {


}

interface Festival {

}

class Date extends Calendar implements SolarTerms, Festival {

}

---------------------------------

TPractice<Date> t1 = new TPractice<Date>(new Date());
t1.showTrueType();

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!