泛型示例三:
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();
文章来源: Java泛型(类型参数T)3――多接口限制