为什么Javac会抱怨命名的自动模块? [英] Why does javac complain about named automatic-modules?

查看:54
本文介绍了为什么Javac会抱怨命名的自动模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果module-info.java引用设置了自动模块名称"的自动模块,为什么Java 9编译器会警告需要自动模块的指令"?这样的模块有什么风险?

Why does the Java 9 compiler warn "requires directive for an automatic module" if module-info.java references automatic modules with "Automatic-Module-Name" set? What's the risk of such modules?

此问题并非什么是自动模块?,因为后者不能解决特定问题我引用的编译器警告背后的原因(问题的上下文很重要).也就是说,这是后续阅读的有用链接.

This question isn't an exact duplicate of What is an automatic module? because the latter does not address the specific reasons behind the compiler warning I have referenced (the context of the question matters). That said, it is a useful link for follow-up reading.

推荐答案

引用雷米·福阿克斯:

主要问题是,自动模块可以从类路径中看到类,但是它也可以导出其所有程序包,因此没有封装,并且一旦需要一个自动模块,则模块路径中的所有自动模块都是可见的.

The main issue is that an automatic module can see classes from the classpath, but it also exports all its package so there is no encapsulation, and once you require one automatic module all automatic modules from the module path are visible.

因此,当您过渡到模块世界时,自动模块是一个很好的工具,但总的来说,您不希望依赖图中有任何自动模块.

So an automatic module is a great tool when you transitioned to the module world, but in fine, you do not want any automatic modules in you dependency graph.

这篇关于为什么Javac会抱怨命名的自动模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆