Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: class+consructor need not be public

...

This compliant solution exports a public static factory method getInstance() that creates and returns a copy of a given MutableClass object instance.

Code Block
bgColor#ccccff
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());
  }
}

...