我了解到,为了使用任何其他导出的模块,我们需要将该模块指定为 requires
:
module mymodule{
requires othermodule.xyz;
}
当 othermodule
在 thirdmodule
上使用并且 mymodule
也需要它时,othermodule
应该像这样定义传递依赖:
module othermodule {
requires transitive thirdmodule
}
但是,我看到很多网站在这种情况下使用public
关键字:
module othermodule {
requires public thirdmodule
}
这两种形式有什么区别?即 需要 public
和 需要 transitive
?
最佳答案
requires public
是在 Java 9 发布之前修订的模块子语言早期版本的一部分。根据 Java 9 JLS,public
ModuleDirective 中不允许使用关键字:参见 JLS 7.7 .
使用 requires public
语法的站点已过时/不正确。这在以下方面得到承认,例如:
- The State of the Module system Mark Reinhold(2016 年 3 月 8 日版本)
基本上 requires public
是过时(现在无效)的语法,requires transitive
是它的替代品。
关于java - 在 Java 9 中要求公共(public) VS 要求传递之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47393126/