实现clone方法
package visitor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { Method method = Instantce .instantce.getClass() .getDeclaredMethod("clone"); method.setAccessible(true); Instantce i =(Instantce) method.invoke(Instantce.instantce); System.out.println(i); } } class Instantce implements Cloneable { public static Instantce instantce = new Instantce(); @Override protected Object clone() throws CloneNotSupportedException { return super.clone(); } }