Created
October 29, 2013 20:10
-
-
Save vyazelenko/7221694 to your computer and use it in GitHub Desktop.
Class that copies itself using clone() method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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