62,616
社区成员
发帖
与我相关
我的任务
分享
private List<E> list;
private List<String> list;
public class Box<T> {
private T t;
private void add(T t) {
this.t = t;
}
public T get() {
return t;
}
public static void main(String[] args) {
Box<Integer> boxInt = new Box<Integer>();
boxInt.add(1);
Integer intResult = boxInt.get();
Box<String> boxStr = new Box<String>();
boxStr.add("Test");
String strResult = boxStr.get();
System.out.println("Integer Result : " + intResult);
System.out.println("String Result : " + strResult);
}
}