【发布时间】:2019-05-27 08:15:45
【问题描述】:
我的代码:
public static void spilledOn (Stack<Object> st1,Stack<Object> st2){
while (!st2.isEmpty()){
st1.push(st2.pop());
}
}
public static int findLengthInStack (Stack<Object> st1){
Stack<Object> tmp=new Stack<>();
int count=0;
while (tmp.isEmpty()){
tmp.push(st1.pop());
count++;
}
toolsForAnything.spilledOn(st1, tmp);
return count;
}
当我调用此方法并使用另一种类型的堆栈时,它无法正常工作
(我的意思是我使用Stack<Integer>)
有没有人对此有任何解决方案?
(我希望它与对象一起使用是正确的)
【问题讨论】:
-
请张贴minimal reproducible example 以准确显示“效果不佳”。
-
public class Stack<E> extends Vector<E>有一个方法size