关于java:代理类生成到本地小妙招

背景

应用动静代理生成的实例,咱们个别是没方法看到的,如果咱们想钻研动静代理的原理的话,还是要看一下这个动静代理实例的代码的,咱们能够这样做,间接上代码

// 代理类
IBuyHouse instance = new IntermediaryProxy().instance(new Homeowner());
try {
    
    // 将代理类转化成字节码数组,而后输入到本地 ,通过jad反编译class文件 (或者间接通过idea 关上class文件)
 byte[] bytes = ProxyGenerator.generateProxyClass(instance.getClass().getSimpleName(), instance.getClass().getInterfaces());
 FileOutputStream fileOutputStream = new FileOutputStream("C:UsersDesktopproxy$Proxy0.class");
 fileOutputStream.write(bytes);
 fileOutputStream.flush();
 fileOutputStream.close();
}catch (Exception e){
    e.printStackTrace();
}

jad反编译工具下载地址:jad

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理