代理类生成到本地小妙招
文章目录
背景
使用动态代理生成的实例,我们一般是没办法看到的,如果我们想研究动态代理的原理的话,还是要看一下这个动态代理实例的代码的,我们可以这样做,直接上代码
// 代理类
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
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论