微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Java 10,Intellij警告(类未导出,正在同一模块中访问)

我试图在我的一个项目中将Java 10与intellij一起使用,并遇到警告.

enter image description here

就是说我不导出服务器类.如果您看到我的程序包结构,则我的服务器位于网络程序包中,我的module-info文件如下所示

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;
}

我故意不导出程序包网络,因为我不想这样做,但是我想在父程序包中的网络程序包中使用类.

他们在这里有好/坏做法,还是只是在疯狂?

最佳答案
如果您要展开警告消息,则会找到其背后的原因

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无效的原因是,没有其他模块可以实例化/访问Server类.

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

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

它将在运行时提供但不在编译时(可能是IntelliJ无法感知的原因)访问包中的公共和受保护类型,并打开这些模块的公共和受保护类型的成员至.

与此相关,如果将opens指令更改为export,则不会再看到IntelliJ的警告.

原文地址:https://www.jb51.cc/java/532856.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐