public final class CloneClass implements Cloneable {
private Date d;
public cloneClassCloneClass(Date d) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
//check permissions
}
this.d = new Date(d.getTime()); //copy-in
}
public Object clone() throws CloneNotSupportedException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
//check permissions
}
final cloneClassCloneClass cloned = (cloneClassCloneClass)super.clone();
cloned.d = new Date( (Date)this.d.getTimeclone() ); //copy mutable Date object
return cloned;
}
public Date getDate() {
return new Date(this.d.getTime()); //copy and return
}
}
|