Manikandan Thiagarajan
asked on
cloneable interface
What is meant by cloneable interface? what is the use
I know if the object is clone that will make a duplicate copy of the object.
what is the use for that one
I know if the object is clone that will make a duplicate copy of the object.
what is the use for that one
It is only used to indicate that the object behaves nicely when you call the clone() method (that is, returns a copy of itself). You have to implement clone() yourself, though.
From the java api documentation (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Cloneable.html):
public interface Cloneable
A class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class.
Invoking Object's clone method on an instance that does not implement the Cloneable interface results in the exception CloneNotSupportedException being thrown.
By convention, classes that implement this interface should override Object.clone (which is protected) with a public method. See Object.clone() for details on overriding this method.
Note that this interface does not contain the clone method. Therefore, it is not possible to clone an object merely by virtue of the fact that it implements this interface. Even if the clone method is invoked reflectively, there is no guarantee that it will succeed.
public interface Cloneable
A class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class.
Invoking Object's clone method on an instance that does not implement the Cloneable interface results in the exception CloneNotSupportedException
By convention, classes that implement this interface should override Object.clone (which is protected) with a public method. See Object.clone() for details on overriding this method.
Note that this interface does not contain the clone method. Therefore, it is not possible to clone an object merely by virtue of the fact that it implements this interface. Even if the clone method is invoked reflectively, there is no guarantee that it will succeed.
ASKER
ur pont is correct
what is the use for that one.
what is the need for copy of the instance
what is the use for that one.
what is the need for copy of the instance
Well, unless your application need to be able to copy objects for some specific reason you probably don't need to care about Cloneable.
ASKER
well
In java packages some predefined objects are cloneable
Most of the EJB objects are cloneable.
What is the specific reason for that ?
In java packages some predefined objects are cloneable
Most of the EJB objects are cloneable.
What is the specific reason for that ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.