java怎么连接另一模块程序,Java模块指令如何影响对模块的反射访问?

exports, exports ... to

uses

provides ... with

open, opens, opens ... to

What (if any) impact does each directive have on an external module accessing internal members using reflection?

For example, does exports allow external modules to access all public, protected, private members of the exported package using reflection? What about the other directives?

解决方案

I would simply quote the #JLS7.7 here (formatted and categorized by me):

Distinct from access at compile time and access at runtime, the Java

SE Platform provides reflective access via the Core Reflection API

(§1.4).

More towards your question categorising as Normal module(module foo) and Open module (open module bar):

Normal Module

A normal module grants reflective access to types in only

those packages which are explicitly exported or explicitly opened (or

both).

the module's exported packages (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.

the module's opened packages (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.

within a module

The code inside the module

enjoys reflective access to all types, and all their members, in all

packages in the module.

Open Module

An open module grants reflective access to types in all its

packages, as if all packages had been opened.

the module's opened packages

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.

within a module

Code inside the module enjoys reflective access to all types,

and all their members, in all packages in the module.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值