Java 10、Intellij警告(class未导出,同模块访问)

Java 10, Intellij Warning (class is not exported, accessing in same module)

我正在尝试在我的一个项目中将 Java 10 与 intellij 一起使用,但遇到了警告。

说我不导出class服务器。如果你看到我的包结构,我在里面有服务器 network 包我的模块信息文件看起来像这样

module core {
    requires com.google.guice;

    requires io.netty.all;

    requires config;

    requires org.apache.logging.log4j;

    exports com.money.heist.server.core;

    opens com.money.heist.server.core.network to com.google.guice;
}

我有意不导出包网络,因为我不想这样做,但我想在父包内的网络包内使用 classes。

他们的任何 good/bad 练习在这里还是只是 intelliJ 发疯了?

如果你展开警告信息,你会找​​到它背后的原因

In addition to that, in Java 9 a module may hide some of its classes by not exporting their packages.

If the public API of a class in an exported package references a class from a non-exported package, such API isn't useful outside of the module.

这样的 API 没有用的原因是没有其他模块可以 instantiate/access Server class。

请注意,在您的模块描述符中,您已经包含了

opens com.money.heist.server.core.network to com.google.guice;

这将在 运行 时提供访问 ,但不在编译时 (可能是 IntelliJ 不感知它的原因),到 publicprotected 包中的类型,以及这些类型的 publicprotected 成员到它们打开的模块。

与上述相关,如果您将 opens 指令更改为 exports,您将不会进一步看到来自 IntelliJ 的警告。