public interface CloneableBean<T> extends Cloneable
Object.clone(). To enable cloning the
bean type needs to extend CloneableBean. clone() will always
return a bean of exactly the same type as the origin bean. Therefore the
generic type parameter must always be set to the declared bean type or at
least to one of its super types. The generic type here gives the advantage of
not having to cast the returned clone.
Example:
public interface Customer extends CloneableBean<Customer> {
...
Attention:
Freezable and you clone a
frozen bean the cloned bean will not be frozen as well.clone() is a method from Object you always
need a dedicated handler for cloning in your IBeanFactory. This needs
to be considered when creating custom factories. If you use IBean
with its default configuration this can be neglected.| Modifier and Type | Method and Description |
|---|---|
T |
clone()
Creates a copy of this bean, having the same field values but having an
initial state on any extension interface.
|
T |
deepClone()
Creates a copy of this bean with the same field values.
|
T clone()
deepClone().T deepClone()
clone()
field values are also cloned with following logic:Cloneable are just cloned but no special deep cloning algorithm
is executed on them.Collection. If the collection is
Cloneable it is cloned. If in addition it is also modifiable deep cloning is also
executed on its elements, that is, all contained elements will be replaced by their deep
clones. A collection is considered as modifiable when it supports methods
Collection.clear() and Collection.add(Object).CloneableBean are recursively deep cloned.Cloneable or CloneableBean is not cloned.
deepClone() has no cycle detection. If you need cycle detection or a more
sophisticated cloning use one of the deep cloning Java frameworks out there.