You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
500 B
Java

Cloning an Object
class MyClass implements Cloneable {
public MyClass() {
}
public Object clone() {
Cloneable theClone = new MyClass();
// Initialize theClone.
return theClone;
}
}
//Here's some code to create a clone.
MyClass myObject = new MyClass();
MyClass myObjectClone = (MyClass)myObject.clone();
//Arrays are automatically cloneable:
int[] ints = new int[]{123, 234};
int[] intsClone = (int[])ints.clone();