大家帮忙看看main方法的泛型使用问题?为什么String和Integer都可以放在里面
public static final Integer MAX_CAPACITY = 1000;
private List<T> tList = new LinkedList<T>();
public StackTest() {
}
/**
* 最大容量為1000
*
* @param t
*/
@NotNull
public void put(T t) {
if (t == null) {
throw new RuntimeException("Element为空");
}
synchronized (this) {
if (tList.size() == MAX_CAPACITY) {
throw new RuntimeException("空间不足");
}
}
this.tList.add(t);
}
public static void main(String[] args) {
StackTest stackTest = new StackTest<Integer>();
stackTest.put(1);
stackTest.put("2");
System.out.println(stackTest.get());
System.out.println(stackTest.pop());
System.out.println(stackTest.pop());
}