Skip to content

Instantly share code, notes, and snippets.

@vyazelenko
Created October 29, 2013 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vyazelenko/7221694 to your computer and use it in GitHub Desktop.
Save vyazelenko/7221694 to your computer and use it in GitHub Desktop.
Class that copies itself using clone() method
package com.vyazelenko.blog.copyobject.primitives.clone;
import com.vyazelenko.blog.copyobject.primitives.BaseClass;
public class CloneCopy extends BaseClass implements Cloneable {
public static final CloneCopy INSTANCE;
static {
INSTANCE = new CloneCopy();
INSTANCE.init();
}
@Override
protected CloneCopy clone() {
try {
return (CloneCopy) super.clone();
} catch (CloneNotSupportedException e) {
throw new Error(e);
}
}
@Override
public CloneCopy copy() {
return clone();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment