Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 1

beside/Java

forked from LiuYan/Java
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
java
/
java9
/
src
/
newFeature
/
Module.java
java
/
java9
/
src
/
newFeature
/
Module.java
Module.java 1.95 KB
Copy Edit Raw Blame History
liuyan authored 2023年05月10日 13:21 +08:00 . java9、java10、java11
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 java9
Class<String> stringClass = String.class;
Field field = stringClass.getDeclaredField("value"); // 通过反射获取String类中value字段
field.setAccessible(true); // 由于是private访问权限,我们修改成可访问权限
System.out.println(field.get("java9"));
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

深入学习Java语言
No labels
Apache-2.0
Use Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/beside/java.git
git@gitee.com:beside/java.git
beside
java
Java
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /