...
Code Block | ||
---|---|---|
| ||
public final class cloneClass implements Cloneable {
private Date d;
public cloneClass(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 cloneClass cloned = (cloneClass)super.clone();
cloned.d = new Date( d.getTime() ); //copy mutable Date object
return cloned;
}
public Date getDate() {
return new Date(this.d.getTime()); //copy and return
}
}
|
...