Prototype mode (implemented Cloneable interface override clone method acquisition target, if the value of the attribute to be changed, it is set to set method)

package designMode;

import javax.lang.model.type.ReferenceType;

RealizeType the implements the Cloneable {class
  public RealizeType () {
    System.out.println ( "particularly successful prototyping");
  }
  public Object clone () throws CloneNotSupportedException {
     System.out.println ( "particularly successful prototype copy!");
     return ( RealizeType) to super.clone ();
  }
}

public class Prototype {

  public static void main(String[] args) throws CloneNotSupportedException {
    // TODO Auto-generated method stub
    RealizeType obj1=new RealizeType();
    RealizeType obj2=(RealizeType)obj1.clone();
    System.out.println("obj1==obj2?"+(obj1==obj2));
  }

}

Guess you like

Origin www.cnblogs.com/Jmublog/p/12203144.html