Question

As I was advised by PMD, I want to reduce coopling by using interfaces instead of implementation ...

In this case, knowing that I need a cloneable param, can I overcome the clone Dilemma (no clone() method in the Cloneable interface) ??

public MyConstructor(ArrayList<E> myParam) {
    this.myAttribute = (ArrayList<E>) myParam.clone();
}
Was it helpful?

Solution

You don't need to clone that way; I'd do it like this:

public MyConstructor(List<E> myParam) 
{
    this.myAttribute = new ArrayList<E>(myParam);
}

OTHER TIPS

I don't know PMD well, but this would be a shallow copy, instead of deep copy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top