gpt4 book ai didi

java - 为什么我不需要 java.base?

转载 作者:行者123 更新时间:2023-12-04 12:36:07 25 4
gpt4 key购买 nike

当我尝试导入时 javax.swing.JFrame ,eclipse 会提示,因为我需要明确地告诉我的包我要从 java.desktop 导入东西。模块。所以我把requires java.desktop在我的 module-info.java然后java编译器知道链接java.desktop东西。我可以放requires java.base在我的 module-info.java也是,但似乎没有必要。我可以 import java.util.Arrays没有它。
eclipse 是不是给我的 javac 添加了一些神奇的酱汁?幕后的选择?是否javac自动要求 java.base ?为什么我不需要要求 java.base ?如果这是编译器魔术,是否还有其他此类特权模块会自动链接到我的包中?
使用 jdk-14,但不确定这是否相关。

最佳答案

这是在 JLS 7.7.1 中指定的:

7.7.1. Dependences
The requires directive specifies the name of a module on which the current module has a dependence.
A requires directive must not appear in the declaration of the java.base module, or a compile-time error occurs, because it is the primordial module and has no dependences (§8.1.4).
If the declaration of a module does not express a dependence on the java.base module, and the module is not itself java.base, then the module has an implicitly declared dependence on the java.base module.


这类似于来自 java.lang 的类的方式。包被隐式导入到源文件中。模块不需要明确声明它们依赖于 java.base模块。

关于java - 为什么我不需要 java.base?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64707985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com