Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正如PMD建议的那样,我想通过使用接口而不是实现来减少合作......
在这种情况下,知道我需要一个可克隆参数,我可以克服克隆困境(接口中没有clone()方法Cloneable)吗?
clone()
Cloneable
public MyConstructor(ArrayList<E> myParam) { this.myAttribute = (ArrayList<E>) myParam.clone(); }
你不需要那样克隆;我会这样做:
public MyConstructor(List<E> myParam) { this.myAttribute = new ArrayList<E>(myParam); }
我不太了解 PMD,但这将是浅拷贝,而不是深拷贝。