java 泛型嵌套:
<pre name="code" class="java">class Info<T,V>{
private T var;
private V value;
public void setVar(T var){
this.var=var;
}
public T getVar(){
return this.var;
}
public void setValue(V value){
this.value=value;
}
public V getValue(){
return this.value;
}
public Info(T var,V value){
this.var=var;
this.value=value;
}
}
class Demo<S>{
private S info;
public void setInfo(S Info){
this.info=info;
}
public S getInfo(){
return this.info;
}
public Demo(S info){
this.info=info;
}
}
public class Fanxingqiantao{
public static void main(String[] args){
Demo<Info<String,Integer>> d = null;//Info 作为Demo的泛型类型
Info<String,Integer> i = null;//实例化Info 类型
i = new Info<String,Integer>("java",1);
d = new Demo<Info<String,Integer>>(i);//添加到Demo中
System.out.println("name:"+ d.getInfo().getVar());
System.out.println("age:"+ d.getInfo().getValue());
}
}