private T var;
private V value;
public InfoDemo(T var, V value){
this.setvalue(value);
this.setvar(var);
}
public void setvar(T var){
this.var = var;
}
public void setvalue(V value){
this.value = value;
}
public T getvar(){
return this.var;
}
public V getvalue(){
return this.value;
}
}
class Demo <S>{
private S InfoDemo;
public Demo(S InfoDemo){
this.setInfo(InfoDemo);
}
public void setInfo(S InfoDemo){
this.InfoDemo = InfoDemo;
}
public S getInfoDemo(){
return this.InfoDemo;
}
}
public class GenericsDemo5 {
public static void main(String[] args) {
InfoDemo<String, Integer> Inf = new InfoDemo<String, Integer>("张三", 30);
Demo<InfoDemo<String, Integer>> Dem = new Demo<InfoDemo<String,Integer>>(Inf);
System.out.println("姓名: " + Inf.getvar());
System.out.println("年龄:" + Inf.getvalue());
System.out.println("姓名: " + Dem.getInfoDemo().getvar());
System.out.println("年龄:" + Dem.getInfoDemo().getvalue());
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。