这段代码问题出在哪里,为什么在运行的时候会出现空指针异常呢,有什么解决的办法吗?
public class Test2{
public static void main(String args[])
{
Stack item=new Stack();
item.push("A");
item.push("B");
item.push("C");
Stack<String> s2 = Stack.copy(item);
while (!s2.isEmpty()) {
System.out.println(s2.pop());
}
}
public static Stack copy(Stack s) {
Stack temp=new Stack();
for(String i:s)
temp.push(i);
Stack temp2=new Stack();
for(String j:temp)
temp2.push(j);
return temp2;
}
}