JDK动态代理Proxy.newProxyInstance()方法生成的代理类源码查看

[复制链接]
查看11 | 回复3 | 2021-1-27 06:49:21 | 显示全部楼层 |阅读模式
Proxy.newProxyInstance(interfaceClass.getClassLoader(),interfaces,handler);jdk的动态代理生成的代理类加入如下代码说是可以保存到本地的,然后可以反编译出来,可是试了一直没有保存到本地的字节码文件啊,
System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles",true);
生成的代理对象$Proxy0的源码想分析一下哪位大神知道,求解
分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:49:21 | 显示全部楼层
Fieldfield=System.class.getDeclaredField("props");
field.setAccessible(true);
Propertiesprops=(Properties)field.get(null);
props.put("sun.misc.ProxyGenerator.saveGeneratedFiles","true");
我加上了这段代码,在IDEA工具里面试了一下,可以生成。
回复

使用道具 举报

千问 | 2021-1-27 06:49:21 | 显示全部楼层
生成的代码路径是啥?我也试了没有啊
回复

使用道具 举报

千问 | 2021-1-27 06:49:21 | 显示全部楼层
新版本JDK做了更改,详情参考https://blog.csdn.net/zyq8514700/article/details/99892329
更改为:System.getProperties().put("jdk.proxy.ProxyGenerator.saveGeneratedFiles","true");
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行