java 统一输入泛型类型

 1 class Info<T>{
2 private T var;
3 public T getVar(){
4 return var;
5 }
6 public void setVar(T var){
7 this.var=var;
8 }
9 public String toString(){
10 return this.var.toString();
11 }
12 }
13 public class GenericsDemo {
14 public static void main(String[] args) {
15 Info<String> i1=new Info<String>();
16 Info<String> i2=new Info<String>();
17 i1.setVar("hello");
18 i2.setVar("LiXinghua");
19 add(i1,i2);
20 }
21 public static <T> void add(Info<T> i1,Info<T> i2){
22 System.out.println(i1.getVar()+" "+i2.getVar());
23 }
24 }

 

posted @ 2012-03-14 20:44  谈笑风生膜法师  阅读(358)  评论(0编辑  收藏  举报