...
This compliant solution exports a public static factory method getInstance()
that creates and returns a copy of a given MutableClass
object instance.
Code Block | ||
---|---|---|
| ||
public final class MutableClass { private final Date date; publicprivate MutableClass(Date d) { this.date = new Date(d.getTime()); // Copy-in } public Date getDate() { return (Date)date.clone(); // Copy and return } public static MutableClass getInstance(MutableClass mc) { return new MutableClass(mc.getDate()); } } |
...