平台模块之间是否允许循环? [英] Are cycles allowed between platform modules?

查看:86
本文介绍了平台模块之间是否允许循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 java.rmi 模块的模块声明:

module java.rmi {
    requires java.base;
    requires java.logging;

    exports java.rmi.activation;
    exports com.sun.rmi.rmid to java.base; // <-- cycle
    ...
}

所以, java.rmi java.base 之间存在循环依赖关系,对吗? 平台模块之间是否允许循环?

So, there is a cyclic dependency between java.rmi and java.base, right? Are cycles allowed between platform modules?

推荐答案

模块系统禁止用静态声明循环,需要子句。这适用于平台和应用程序模块,您提供的示例不违反该规则。

The module system forbids statically declaring cycles with requires clauses. This is true for platform and application modules and the example you give does not violate that rule.

要求子句只是模块图中可读性边缘的一个来源。其他是命令行标志,反射,需要传递,我相信还有更多。添加所有这些可能会导致模块图中的循环并且不会被禁止。

Requires clauses are just one source for readability edges in the module graph, though. Others are command line flags, reflection, requires transitive, and I'm sure there are more. Adding all these may result in cycles in the module graph and that is not forbidden.

在具体示例中,循环仅创建一次 java.base 读取 java.rmi ,如果它在 com.sun.rmi.rmid 中的类上使用反射,就会发生这种情况。

In your concrete example the cycle is only created once java.base reads java.rmi, which could happen if it uses reflection on classes in com.sun.rmi.rmid.

这篇关于平台模块之间是否允许循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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