Skip to content

Instantly share code, notes, and snippets.

@MykolaBova
Last active August 29, 2015 14:06
Show Gist options
  • Save MykolaBova/330075741ffdf05fd836 to your computer and use it in GitHub Desktop.
Save MykolaBova/330075741ffdf05fd836 to your computer and use it in GitHub Desktop.
ClonePerson
public class ClonePerson {
private String name;
public ClonePerson(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static void main(String[] args) {
ClonePerson p = new ClonePerson("Sam");
try {
// Person class doesn't implement Cloneable but tries to get clone. It fails
// with CloneNotSupportedException
ClonePerson pClone = (ClonePerson) p.clone();
System.out.println(pClone.getName());
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment