gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 02:35:44 24 4
gpt4 key购买 nike

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

  • 导出,导出...到
  • 使用
  • 提供...
  • 打开,打开,打开...

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

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

最佳答案

我只想引用 #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.

关于java - Java 模块指令如何影响对模块的反射访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53927375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com