背景
使用动态代理生成的实例,我们一般是没办法看到的,如果我们想研究动态代理的原理的话,还是要看一下这个动态代理实例的代码的,我们可以这样做,直接上代码
// 代理类
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
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。