泛型的嵌套

class InfoDemo <T, V>{
 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());
 }
}
posted @ 2013-08-14 21:47  peng_gy  阅读(92)  评论(0编辑  收藏  举报