public class Ctrl {
LinkedStack<T> x = new LinkedStack<T>();我第一次尝试使用泛型,我得到了错误“这行的多个标记-T不能解析为一个类型”的行above.What,不是吗?
public class LinkedStack<E> {
private static class LinkedNode<T>
{
private T item;
private LinkedNode<T> next;
private LinkedNode(T value)
{
item = value;
next = null;
}
private LinkedNode(T value, LinkedNode<T> reference)
{
item = value;
next = reference;
}
}
protected LinkedNode<E> top;
public LinkedStack()
{
top = null; // empty stack
}发布于 2013-11-24 23:12:26
在任何地方都使用相同类型的参数名。
然后将其作为参数添加到Ctrl类中。
public class Ctrl<T> {
LinkedStack<T> x = new LinkedStack<T>();现在,所有具体的实现都必须定义T。例如:
public class AppCtrl extends Ctrl<Integer> {
}或者用具体类型实例化它。
Ctrl myctrl = new Ctrl<Integer>();// + necessary constructor params或者如果您不想传递它,请在Ctrl中直接指定它
public class Ctrl {
LinkedStack<Integer> x = new LinkedStack<Integer>();https://stackoverflow.com/questions/20182298
复制相似问题