This action will force synchronization from LiuYan/Java, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
package newFeature;import java.lang.reflect.Field;/*** @Author: LiuYan* @Date: 2023年3月12日 20:04* 主要是API的优化,如支持HTTP2的Client API、JVM采用G1为默认垃圾收集器* 1、模块化:* (1)反射API的Java9封装和安全性得到了改进,如果模块没有明确授权给其他模块使用反射的权限,那么其他模块是不允许使用反射进行修改的,Unsafe类玩不转了* (2)模块机制:* 系统模块:来自JDK和JRE的模块(官方提供的模块,我们平时导用的)* 应用程序模块:自己写的Java模块项目* 自动模块:有些库不是Java9以上的模块项目,要做兼容,默认情况下直接导出所有的包,可以访问所有其他模块提供的类,兼容老版本* 未命名模块:传统Java8以下的编程模式,因为没有模块只需要导包就行,兼容老版本* (3)指定模块暴露:* export com.test to module.b 使用exports将com.test包下所有内容暴露出去,这样其他模块才能导入* requires transitive java.logging 使用transitive来向其他模块传递此依赖* opens com.test 通过使用opens关键字来为其他模块开放反射权限* uses com.test.Test 使用uses指定,Test是一个接口(比如需要的服务等),模块需要使用到* provides com.test.Test with com.main.TestImpl 声明此模块提供了Test的实现类*/public class Module {public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {// Unable to make field private final byte[] java.lang.String.value accessible: module java.base does not "opens java.lang" to module java9Class<String> stringClass = String.class;Field field = stringClass.getDeclaredField("value"); // 通过反射获取String类中value字段field.setAccessible(true); // 由于是private访问权限,我们修改成可访问权限System.out.println(field.get("java9"));}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。