Generic type test java

 

package test;

public class GenericTest {

public class Room<T> {
private T t;
public void add(T t){
this.t=t;
}
public T get(){
return t;
}
}


public static void main(String[] args) {
GenericTest g=new GenericTest();
Room<Integer> i=g.new Room<Integer>();
i.add(100);
System.out.println(i.get());

Room<String> s=g.new Room<String>();
s.add("s300");
System.out.println(s.get());
}
}

 

posted on 2017-05-17 17:01  rojas  阅读(131)  评论(0编辑  收藏  举报