import java.util.ArrayList;
public class MyStack<T> {
private ArrayList<T> stack;
// Copy constructor
public MyStack(MyStack<T> s) {
// i know its wrong
for(int i = 0; i < stack.size(); i++) {
this.stack.get(i) = s.stack.get(i);
}
}
}
最佳答案
怎么样
// Copy constructor
public MyStack(MyStack<T> s) {
this.stack = new ArrayList<T>(s.stack);
}
关于java - 如何实现通用数组列表复制构造函数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19351778/