【发布时间】:2018-10-02 05:09:36
【问题描述】:
我正在尝试使用堆栈将对象放入堆栈中。我有一个 Pixel 类,它有一个简单的 getX 函数,它返回构造函数中定义的变量。当我使用 stack.peek().getX();它说它找不到 .getX() 的符号;
Stack stack = new Stack();
Pixel first = new Pixel(colorX,colorY);
stack.push(first);
int x = stack.peek().getX();
我是否使用了 peek 功能错误?还是我的 Pixel 类设置不正确?
public class Pixel {
private int x, y , count = 0;
Pixel(int x_in, int y_in)
{
x = x_in;
y = y_in;
}
public int getX(){return x;}
public int getY(){return y;}
【问题讨论】: