Java 模块指令如何影响对模块的反射访问?

How do Java Module directives impact reflection access into a module?

根据https://www.oracle.com/corporate/features/understanding-java-9-modules.html,Java模块系统引入了以下指令:

每个指令对使用反射访问内部成员的外部模块有什么影响(如果有的话)?

例如,exports <package>是否允许外部模块使用反射访问导出包的所有publicprotectedprivate成员?其他指令呢?

我在这里简单地引用#JLS7.7(由我格式化和分类):

Distinct from access at compile time and access at runtime, the Java SE Platform provides reflective access via the Core Reflection API (§1.4).

更多关于你的问题分类为普通模块(module foo)和开放模块(open module bar):

普通模块

A normal module grants reflective access to types in only those packages which are explicitly exported or explicitly opened (or both).

  • 模块的导出包(exports com.example.foo.bar)

    For code outside a normal module, the reflective access granted to types in the module's exported (and not opened) packages is specifically to the public and protected types in those packages, and the public and protected members of those types.

  • 模块打开的包(opens com.example.foo.internal to com.example.bar)

    The reflective access granted to types in the module's opened packages (whether exported or not) is to all types in those packages, and all members of those types.

    No reflective access is granted to types, or their members, in packages which are not exported or opened.

  • 在一个模块内

    The code inside the module enjoys reflective access to all types, and all their members, in all packages in the module.

打开模块

An open module grants reflective access to types in all its packages, as if all packages had been opened.

  • 模块打开的包

    For code outside an open module, the reflective access granted to types in the module's opened packages (that is, all packages in the module) is to all types in those packages, and all members of those types.

  • 在一个模块内

    Code inside the module enjoys reflective access to all types, and all their members, in all packages in the module.