Geek

博客园 首页 新随笔 联系 订阅 管理

实现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();
    }
    
    
}

 

posted on 2020-03-24 13:38  .geek  阅读(193)  评论(0编辑  收藏  举报