java 设置嵌套泛型

 1 class Info{
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{
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> d=null;
37 Info i=null;
38 i=new Info("Lixinghua",30);//注意此处
39 d=new Demo>(i);//注意此处
40 System.out.println("content1:"+d.getInfo().getVar());
41 System.out.println("content2:"+d.getInfo().getValue());
42 }
43 }

 

转载于:https://www.cnblogs.com/dennisac/archive/2012/03/14/2396569.html

你可能感兴趣的:(java 设置嵌套泛型)