加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 19:26:09 所属栏目:Java 来源:网络整理
导读:我试图在我的一个项目中将Java 10与intellij一起使用,并遇到警告. 就是说我不导出服务器类.如果您看到我的程序包结构,则我的服务器位于网络程序包中,我的module-info文件如下所示 module core { requires com.google.guice; requires io.netty.all; requires

我试图在我的一个项目中将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的警告.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读