编译错误“不兼容的类型 - 找到java.lang.Object但是期望的E”是在我尝试以这种形式编译代码时生成的:
public class E {
private int x;
public E {
x = 0;
}
}
public class Class {
private E o;
private E b;
private Stack stack = new Stack();
public void foo() {
stack.push(o);
}
public void bar() {
**b = stack.pop();**
}
}
答案 0 :(得分:5)
您可以声明堆栈包含E
s:
private Stack<E> stack = new Stack<E>();
答案 1 :(得分:2)
尝试施放到E.
public void bar() {
b = (E)stack.pop();
}