How to clone a JavaBean without using the Cloneable interface

This example shows how to clone a JavaBean using the BeanUtils class of the Apache Commons Beanutils library. The BeanUtils class can clone a JavaBean even though it does not implement the Cloneable interface, which normally must be done for a clone operation to work.

First we create an instance of the JavaBean ‘Car’. The instance is passed to the static method cloneBean of the BeanUtils class. Since the value returned is of type Object we need to cast it to a Car instance. Finally we use a BeanMap to iterate over the properties of the cloned bean to see their values.

To see the Car class, follow this link:

Using BeanMap class from Apache Commons Beanutils

The output from the code above is:

Search for more Java info on this site here:
Custom Search

Please type any questions here.