我正试图通过一个类实现iSortableStack接口。什么导致“不兼容的操作数类型”错误?
这是我的主要功能,
public class SampleStack<E> {
E ch;
@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
ISortableStack<Character> s = new SortableStack<Character>();
SampleStack demo = new SampleStack();
while ((demo.ch == System.in.read()) != '\n')
if (!s.isFull())
s.push((Character) demo.ch);
while (!s.isEmpty())
System.out.print(s.pop());
System.out.println();
}
}
但我得到一个错误,在这条线上,
while ((demo.ch == System.in.read()) != '\n')
错误:不兼容的操作数类型的对象和int
是什么这里错了吗?
,如果你申报演示为'SampleStack'? –
而不是抑制警告(如你用'@SuppressWarnings完成(“未登记”)'),你应该听从编译器的建议。如果你不明白这个建议,那么你应该先读一读,直到你这样做(这就是你在做什么,这是一个很好的选择。)一般来说:*不要忽视警告,除非你知道他们的意思* – dlev
到底什么是排序堆,比一个自相矛盾的其他? – EJP