【发布时间】:2014-05-04 05:21:22
【问题描述】:
嗨 Stack Overflow 社区 ^_^
基本上,我正在使用 Stacks 并将中缀方程转换为后缀方程。 这是我尝试编译 Stack 类时屏幕上显示的错误消息:
Stack.java:5: error: type argument T#1 is not within bounds of type-variable T#2
private LinkedList<T> list;
^
where T#1,T#2 are type-variables:
T#1 extends Object declared in class Stack
T#2 extends Comparable<T#2> declared in class LinkedList
我在试图找出这个错误时遇到了真正的麻烦,但遗憾的是我不知道可能是什么问题。如果我知道得更好一点,我可以为您提供更多信息。
提前感谢任何 cmets 和帮助!
更新:这是我的课...
package ListPkg;
public class Stack<T> // implements Comparable<Stack>>
{
private LinkedList<T> list;
public Stack()
{
this("list");
}
public Stack(String name)
{
list = new LinkedList(name);
}
public void push(T item)
{
list.insertAtFront(item);
}
public T pop()
{
list.removeFromFront();
}
public int lenghtIs()
{
return list.lengthIs();
}
public T peek()
{
return list.returnFirstNode();
}
public void print()
{
list.print();
}
public boolean isEmpty()
{
return list.isEmpty();
}
}
【问题讨论】: