package 泛型;
/**
* 泛型的继承 4种情况
* 1.全部继承 Father<T1,T2>{} my<T1,T2,T3> extends Father<T1,T2>{}
* 2.部分继承 就是在继承的时候,给父类的泛型进行实例化
* Father<T1,T2>{}
* my<T1,T2,T3> extends Father<T1,String>{}
* 3.实现父类泛型,就是子类在继承反向的时候,全部实现了父类的泛型
* Father<T1,T2>{}
* my<T1,T2,T3> extends Father<String,String>{}
* 4.不实现父类的泛型,
* Father<T1,T2>{}
* my<T1,T2,T3> extends Father{} 这个时候默认为object
* author 小虎牙
*
*/
public class fanxing1 {
public static void main(String[] args) {
Father<Integer, String> father = new child<>(123, "你好");
System.out.println(father);
child<Integer, String, Boolean> child = new child<>(123, false);
System.out.println(child);
}
}
class Father<T1, T2> {
T1 t1;
T2 t2;
public Father(T1 t1, T2 t2) {
this.t1 = t1;
this.t2 = t2;
System.out.println("t1的类型" + this.t1.getClass());
System.out.println("t2的类型" + this.t2.getClass());
}
@Override
public String toString() {
// TODO 自动生成的方法存根
return "这个是爸爸";
}
}
// 这里继承和顺序没有关系,只和名字有关系
class child<T1, T3, T2> extends Father<T1, T2> {
T1 t1;
T2 t2;
@Override
public String toString() {
// TODO 自动生成的方法存根
return "这是孩子";
}
public child(T1 t1, T2 t2) {
super(t1, t2);
}
}