需求和要求静态的模块声明之间有什么区别 [英] What's the difference between requires and requires static in module declaration

查看:112
本文介绍了需求和要求静态的模块声明之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模块声明中 需要 需要静态 模块语句之间的区别是什么?

What's the difference between requires and requires static module statements in module declaration?

例如:

module bar {
    requires java.compiler;
    requires static java.base;
}


推荐答案

A requires 子句表示在编译和运行时需要所需的模块。因此,当模块系统在模块解析期间遇到这样的条款时(处理模块描述符和依赖关系的阶段)它搜索可观察模块的范围(JDK中的模块和模块路径上的模块),如果找不到模块则抛出错误。

A requires clause expresses that the required module is needed at compile and run time. Consequently, when the module system encounters such a clause during module resolution (the phase in which module descriptors are processed and dependencies are resolved) it searches the universe of observable modules (the modules in the JDK and on the module path) and throws an error if it doesn't find the module.

A 需要静态子句表示在运行时可选的依赖项。这意味着在编译时模块系统的行为完全如上所述。

A requires static clause expresses a dependency that is optional at run time. That means at compile time the module system behaves exactly as described above.

在运行时,另一方面,它主要忽略需要静态子句。如果遇到一个,无法解决。这意味着,如果一个可观察模块仅以引用需要静态,则它不会进入模块图形!起初这可能有点令人惊讶。另一方面,如果模块以其他方式进入图形(某些其他模块需要,使用手动添加 - add-modules ,由服务绑定),所有具有可选依赖关系的模块都可以阅读它。

At run time, on the other hand, it mostly ignores requires static clauses. If it encounters one, it does not resolve it. That means, if an observable module is only referenced with requires static, it does not make it into the module graph! This can be a little surprising at first. If, on the other hand, the module makes it into the graph in some other way (required by some other module, added manually with --add-modules, drawn in by service binding), all modules that have an optional dependency on it can read it.

这篇关于需求和要求静态的模块声明之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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