import java.util.ArrayList;
class Stack {
private ArrayList stack;
private int pos;
Stack() {
stack = new ArrayList();
pos = -1;
}
int pop() {
if(pos < 0) {
System.out.println("Stack underflow.");
return 0;
}
int out = stack.get(pos);
stack.remove(pos);
pos--;
return out;
}
}
我正在尝试编写一个基本的可变长度堆栈,这是我的代码片段。当我运行它时,我得到一个错误:
Main.java:16: error: incompatible types
int out = stack.get(pos);
^
required: int
found: Object
为什么这被作为对象传递?