Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>clone()</code> makes a shallow clone - it copies only the first level of fields. You should avoid using <code>clone()</code> and <code>Cloneable</code>, because it is very hard to implement it correctly, and it is very likely that something will be broken, although not immediately visible. See <a href="http://www.artima.com/intv/bloch13.html" rel="noreferrer">what Joshua Bloch</a> says about this.</p> <p>If you want deep copy - i.e. the whole object hierarchy being cloned, I can suggest two options:</p> <ul> <li>if your objects implements <code>Serializable</code>, use <a href="http://commons.apache.org/lang/api/org/apache/commons/lang/SerializationUtils.html#clone%28java.io.Serializable%29" rel="noreferrer"><code>SerializationUtils.clone(..)</code></a> (from <a href="http://commons.apache.org/lang/" rel="noreferrer">commons-lang</a>)</li> <li>if it's not serializable, then try <a href="http://robust-it.co.uk/clone/" rel="noreferrer">java deep cloning library</a></li> </ul> <p>If however, you want shallow copy - i.e. you still want all your fields copied to a new object, but the fields, and the fields' fields (etc..) point to their original values, then you can use <a href="http://commons.apache.org/beanutils/v1.8.3/apidocs/org/apache/commons/beanutils/BeanUtils.html#cloneBean%28java.lang.Object%29" rel="noreferrer"><code>BeanUtils.clone(..)</code></a> (from <a href="http://commons.apache.org/beanutils/" rel="noreferrer">commons-beanutils</a>)</p> <p>Apart from the cloning matter - having 100 member variables isn't a good sign. Consider splitting your class into multiple classes (update: and multiple tables, using foreign keys. Of course, if that is applicable. If these are truly properties of the same object, then fine)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload