What's the preferred way to assign a collection from a parameter?
<p>I have this class:</p>

<pre><code>public MyClass {
    public void initialize(Collection&lt;String&gt; data) {
        this.data = data; // &lt;-- Bad!
    }
    private Collection&lt;String&gt; data;
}
</code></pre>

<p>This is obviously bad style, because I'm introducing a shared mutable state. What's the preferred way to handle this?</p>

<ul>
<li>Ignore it?</li>
<li>Clone the collection?</li>
<li>...?</li>
</ul>

<p><strong>EDIT:</strong> To clarify why this is bad, imagine this:</p>

<pre><code>MyClass myObject = new MyClass();
List&lt;String&gt; data = new ArrayList&lt;String&gt;();
myObject.initialize(data); // myObject.data.size() == 0
data.add("Test"); // myObject.data.size() == 1 
</code></pre>

<p>Just storing the reference poses a way to inject data into the private field <code>myObject.data</code>, although it should be completely private.</p>

<p>Depending on the nature of <code>MyClass</code> this could have serious impacts.</p>
