1 class Info<T,V>{
2 private T var;
3 private V value;
4 public Info(T var,V value){
5 this.setVar(var);
6 this.setValue(value);
7 }
8 public T getVar() {
9 return var;
10 }
11 public void setVar(T var) {
12 this.var = var;
13 }
14 public V getValue() {
15 return value;
16 }
17 public void setValue(V value) {
18 this.value = value;
19 }
20
21 }
22 class Demo<S>{
23 private S info;
24 public Demo(S info){
25 this.setInfo(info);
26 }
27 public S getInfo() {
28 return info;
29 }
30 public void setInfo(S info) {
31 this.info = info;
32 }
33 }
34 public class GenericsDemo {
35 public static void main(String[] args) {
36 Demo<Info<String,Integer>> d=null;
37 Info<String,Integer> i=null;
38 i=new Info<String,Integer>("Lixinghua",30);//注意此处
39 d=new Demo<Info<String,Integer>>(i);//注意此处
40 System.out.println("content1:"+d.getInfo().getVar());
41 System.out.println("content2:"+d.getInfo().getValue());
42 }
43 }