Java語言規範基於JavaSE9 第七章 包和模塊(八)

7.7 Module Declarations

7.7 模塊聲明

A module declaration specifies a new named module. A named module specifies dependences on other modules to define the universe of classes and interfaces available to its own code; and specifies which of its packages are exported or opened in order to populate the universe of classes and interfaces available to other modules which specify a dependence on it.

模塊聲明指定了一個新的具名模塊。具名模塊指定了對其他模塊的依賴關係,以定義可用於其自己的代碼的類和接口的範圍;並且指定將其中哪些包導出或打開,以便填充對指定與其有依賴性的其他模塊的可用類和接口的範圍。

A “dependence” is what is expressed by a requires directive, independent of whether a module exists with the name specified by the directive. A “dependency” is the observable module enumerated by resolution (as described in the java.lang.module package specification) for a given requires directive. Generally, the rules of the Java programming language are more interested in dependences than dependencies.

“依賴”是指由需求指令表示的內容,與模塊是否存在指令指定的名稱無關。“依賴關係”是指根據給定的需求指令決定(如java.lang.module包規範中所述)而枚舉出可觀察模塊。通常來講,Java編程語言的規則更注重依賴而不是依賴關係。

ModuleDeclaration:
{Annotation} [open] module Identifier {. Identifier}
  { {ModuleDirective} }

A module declaration introduces a module name that can be used in other module declarations to express relationships between modules. A module name consists of one or more Java identifiers (§3.8) separated by “.” tokens.

模塊聲明引入了一個模塊名稱,它可以在其他模塊聲明中使用來表示模塊之間的關係。模塊名稱由一個或多個Java標識符(第3.8節)通過符號“.”分隔組成。

There are two kinds of modules: normal modules and open modules. The kind of a module determines the nature of access to the module’s types, and the members of those types, for code outside the module.

模塊有兩種種類:正常模塊和開放模塊。模塊的種類決定了對模塊類型的訪問的性質,以及這些類型的成員對模塊外的代碼的性質。

A normal module, without the open modifier, grants access at compile time and run time to types in only those packages which are explicitly exported.

不帶有open修飾符的普通模塊在編譯時和運行時只允許訪問顯式導出的包中的類型。

An open module, with the open modifier, grants access at compile time to types in only those packages which are explicitly exported, but grants access at run time to types in all its packages, as if all packages had been exported.

帶有open修飾符的開放模塊在編譯時只允許訪問顯式導出的包中的類型;而在運行時允許訪問模塊中所有包的類型,就像所有包都被導出一樣。

For code outside a module (whether the module is normal or open), the access granted at compile time or run time to types in the module’s exported packages is specifically to the public and protected types in those packages, and the public and protected members of those types (§6.6). No access is granted at compile time or run time to types, or their members, in packages which are not exported. Code inside the module may access public and protected types, and the public and protected members of those types, in all packages in the module at both compile time and run time.

對於模塊(無論是普通模塊還是開放模塊)外代碼來說,在編譯時或運行時,允許訪問的模塊導出包中的類型具體爲這些包中的public和protected類型以及這些類型中的public和protected成員;不允許訪問模塊中不是導出包的類型或者它們的成員。模塊內代碼在編譯時和運行時可以訪問模塊中所有包的public和protected類型以及這些類型中的public和protected成員。

Distinct from access at compile time and access at run time, the Java SE Platform provides reflective access via the Core Reflection API (§1.4). A normal module grants reflective access to types in only those packages which are explicitly exported or explicitly opened (or both). An open module grants reflective access to types in all its packages, as if all packages had been opened.

與編譯時訪問和運行時訪問不同,Java SE平臺通過核心反射API(第1.4節)提供了反射訪問。普通模塊只允許反射訪問模塊中那些顯式導出或顯式開放(或兩者)的包中的類型。開放模塊允許反射訪問模塊中的所有包中的類型,就像所有包都被導出一樣。

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 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. Code inside the module enjoys reflective access to all types, and all their members, in all packages in the module.

對於普通模塊外代碼來說,允許反射訪問模塊的導出(不是開放)包中的類型具體爲這些包中的public和protected類型以及這些類型中的public和protected成員;允許反射訪問模塊的開放包(無論是否導出)中的所有類型以及這些類型中的所有成員;不允許反射訪問那些模塊中不是導出或開放的包的類型或它們的成員。模塊內代碼能夠反射訪問模塊中所有包中的所有類型以及它們所有的成員。

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.

對於開放模塊外代碼來說,允許反射訪問模塊的開放包(即模塊中的所有包)中的所有類型以及這些類型中的所有成員。模塊內代碼能夠反射訪問模塊中所有包中的所有類型以及它們的所有成員。

The directives of a module declaration specify the module’s dependences on other modules (via requires, §7.7.1), the packages it makes available to other modules (via exports and opens, §7.7.2), the services it consumes (via uses, §7.7.3), and the services it provides (via provides, §7.7.4).

模塊聲明的指令指定了模塊對其他模塊的依賴(通過requires指令,第7.7.1節);它對其他模塊可用的包(通過exports和opens指令,第7.7.2節);它使用的服務(通過uses指令,第7.7.3節);它提供的服務(通過provides指令,第7.7.4節)。

ModuleDirective:
requires {RequiresModifier} ModuleName ;
exports PackageName [to ModuleName {, ModuleName}] ;
opens PackageName [to ModuleName {, ModuleName}] ;
uses TypeName ;
provides TypeName with TypeName {, TypeName} ;

RequiresModifier:
(one of)
transitive static

If and only if packages are stored in a file system (§7.2), the host system may choose to enforce the restriction that it is a compile-time error if a module declaration is not found in a file under a name composed of module-info plus an extension (such as .java or .jav).

當且僅當包存儲在文件系統(第7.2節)中時,如果在由module-info加上擴展名(例如.java或.jav)組成的名稱的文件中找不到模塊聲明,則主機系統可能會強制產生一個編譯時錯誤。

To aid comprehension, it is customary, though not required, for a module declaration to group its directives, so that the requires directives which pertain to modules are visually distinct from the exports and opens directives which pertain to packages, and from the uses and provides directives which pertain to services. For example:

爲了幫助理解,習慣上(儘管不是必需的)在模塊聲明中對其指令進行分組,以便讓與模塊有關的requires指令、與包有關的exports和opens指令、與服務有關的的uses和provides指令看起來有所區分。例如:

module com.example.foo {
    requires com.example.foo.http; 
    requires java.logging;
    requires transitive com.example.foo.network; 
    exports com.example.foo.bar;
    exports com.example.foo.internal to com.example.foo.probe;

    opens com.example.foo.quux;
    opens com.example.foo.internal to com.example.foo.network,
    com.example.foo.probe;

    uses com.example.foo.spi.Intf;
    provides com.example.foo.spi.Intf with com.example.foo.Impl;
}

The opens directives can be avoided if the module is open:

如果模塊是開放的,那麼opens指令可以避免。

open module com.example.foo { 
    requires com.example.foo.http; 
    requires java.logging;
    requires transitive com.example.foo.network; 
    exports com.example.foo.bar;
    exports com.example.foo.internal to com.example.foo.probe;

    uses com.example.foo.spi.Intf;
    provides com.example.foo.spi.Intf with com.example.foo.Impl;
}

Development tools for the Java programming language are encouraged to highlight requires transitive directives and unqualified exports directives, as these form the primary API of a module.

建議Java程序語言開發工具高亮顯示來自模塊的主API的 requires transitive指令和非限定的exports指令。

7.7.1 Dependences

7.7.1 依賴

The requires directive specifies the name of a module on which the current module has a dependence.

requires指令指定了被當前模塊依賴的模塊的名稱。

A requires directive must not appear in the declaration of the java.base module, or a compile-time error occurs, because it is the primordial module and has no dependences (§8.1.4).

requires指令不能在java.base模塊聲明出現,否則會發生編譯時錯誤,因爲該模塊是初始模塊不存在依賴關係。

If the declaration of a module does not express a dependence on the java.base module, and the module is not itself java.base, then the module has an implicitly declared dependence on the java.base module.

如果模塊聲明不明確表示對java.base模塊的依賴,並且該模塊不是java.base本身,那麼該模塊隱式聲明依賴於java.base模塊。

The requires keyword may be followed by the modifier transitive. This causes any module which requires the current module to have an implicitly declared dependence on the module specified by the requires transitive directive.

requires關鍵字後可以跟着修飾符transitive。這將導致依賴於當前模塊的任何模塊隱式地依賴於被requires transitive指令指定的模塊。

The requires keyword may be followed by the modifier static. This specifies that the dependence, while mandatory at compile time, is optional at run time.

requires關鍵字後可以跟着修飾符static。這樣就指定了依賴的模塊在編譯時是必需的,而在運行時是可選的。

It is a compile-time error if more than one requires directive in a module declaration specifies the same module name.

如果在模塊聲明中有多個requires指令指定了相同的模塊名,則會產生編譯時錯誤。

It is a compile-time error if resolution, as described in the java.lang.module package specification, with the current module as the only root module, fails for any of the reasons described in the java.lang.module package specification.

如果像在java.lang.module包規範中描述的解決方案一樣,當前模塊作爲唯一的根模塊,由於java.lang.module包規範中描述的任何原因而失敗,那麼會產生編譯時錯誤。

For example, if a requires directive specifies a module that is not observable, or if the current module directly or indirectly expresses a dependence on itself.

例如,如果requires指令指定了一個不可觀察的模塊,或者當前模塊直接或間接地表示了對自身的依賴。

If resolution succeeds, then its result specifies the modules that are read by the current module. The modules read by the current module determine which ordinary compilation units are visible to the current module (§7.3). The types declared in those ordinary compilation units (and only those ordinary compilation units) may be accessible to code in the current module (§6.6).

如果解析成功,則其結果是指定由當前模塊讀取的模塊。當前模塊讀取的模塊能夠確定哪些普通編譯單元對當前模塊可見(第7.3節)。在那些普通編譯單元中聲明的類型(僅限那些普通編譯單元)可以被當前模塊(第6.6節)中的代碼訪問。

The Java SE Platform distinguishes between named modules that are explicitly declared (that is, with a module declaration) and named modules that are implicitly declared (that is, automatic modules). However, the Java programming language does not surface the distinction: requires directives refer to named modules without regard for whether they are explicitly declared or implicitly declared.

Java SE平臺區分顯式聲明的具名模塊(即模塊聲明)和隱式聲明的具名模塊(即自動模塊)。但是,Java編程語言並沒有表現出這樣的區別:requires指令引用指定的具名模塊,而不考慮它們是否被顯式聲明或隱式聲明。

While automatic modules are convenient for migration, they are unreliable in the sense that their names and exported packages may change when their authors convert them to explicitly declared modules. A Java compiler is encouraged to issue a warning if a requires directive refers to an automatic module. An especially strong warning is recommended if the transitive modifier appears in the directive.

雖然自動模塊便於遷移,但是它們的名稱和導出包可能在其作者將它們轉換成顯式聲明的模塊時發生改變,所以它們是不可靠的。建議Java編譯器在requires指令引用了自動模塊時發出警告。如果transitive修飾符出現在指令中的話,則建議使用特強級別的警告。

Example 7.1.1-1. Resolution of requires transitive directives

例7.1.1-1. requires transitive指令解決方案

Suppose there are four module declarations as follows:

假設有4個模塊聲明如下:

module m.A {
    requires m.B;
}

module m.B {
    requires transitive m.C;
}

module m.C {
    requires transitive m.D;
}

module m.D {
    exports p;
}

where the package p exported by m.D is declared as follows:

其中由m.D導出的包p的聲明如下:

package p;
public class Point {}

and where a package client in module m.A refers to the public type Point in the exported package p:

以及模塊m.A中的包client引用導出的包p中的public類型Point:

package client; 
import p.Point; 
public class Test {
    public static void main(String[] args) {
         System.out.println(new Point());
    }
}

The modules may be compiled as follows, assuming that the current directory has one subdirectory per module, named after the module it contains:

假設當前目錄下每個模塊有一個子目錄,以其包含的模塊命名,模塊可能編譯如下:

javac --module-source-path . -d . --module m.D 
javac --module-source-path . -d . --module m.C
javac --module-source-path . -d . --module m.B 
javac --module-source-path . -d . --module m.A

The program client.Test may be run as follows:

程序client.Test可能運行如下:

java --module-path . --module m.A/client.Test

The reference from code in m.A to the exported public type Point in m.D is legal because m.A reads m.D, and m.D exports the package containing Point. Resolution determines that m.A reads m.D as follows:

m.A中的代碼對m.D中導出的public類型Point的引用是合法的,因爲m.A讀取m.D,並且m.D導出了包含Point的包。確定m.A讀取m.D的解決方案如下:

• m.A requires m.B and therefore reads m.B.

• m.A requires m.B因此讀取m.B。

• Since m.A reads m.B, and since m.B requires transitive m.C, resolution determines that m.A reads m.C.

• 由於m.A讀取m.B而且m.B requires transitive m.C,解決方案確定m.A讀取m.C。

• Then, since m.A reads m.C, and since m.C requires transitive m.D, resolution determines that m.A reads m.D.

• 那麼,由於m.A讀取m.C而且m.C requires transitive m.D,解決方案確定m.A讀取m.D。

In effect, a module may read another module through multiple levels of dependence, in order to support arbitrary amounts of refactoring. Once a module is released for someone to reuse (via requires), the module’s author has committed to its name and API but is free to refactor its content into other modules which the original module reuses (via requires transitive) for the benefit of consumers. In the example above, package p may have been exported originally by m.B (thus, m.A requires m.B) but refactoring has caused some of m.B’s content to move into m.C and m.D. By using a chain of requires transitive directives, the family of m.B, m.C, and m.D can preserve access to package p for code in m.A without forcing any changes to the requires directives of m.A. Note that package p in m.D is not “re-exported” by m.C and m.B; rather, m.A is made to read m.D directly.

實際上,模塊可以通過多個級別的依賴來讀取另一個模塊,以支持任意數量的重構。一旦一個模塊被髮布以供他人複用(通過requires),模塊的作者承諾模塊名和API可以自由重寫它的內容到那些爲了消費者的利益而重用(通過requires transitive)初始模塊的其他模塊。在上面的例子中,包p可能原本是由m.B導出的(因此,m.A requires m.B),但是重構導致了m.B的一些內容遷移到了m.C和m.D。通過使用requires transitive指令鏈,m.B、m.C和m.D的屬族可以對m.A中的代碼保留訪問包p的權限,而無需強制對m.A的requires指令進行任何更改。注意,m.D中的包p不是由m.C和m.B“重導出”的;相反,m.A是直接讀取m.D的。

7.7.2 Exported and Opened Packages

7.7.2 導出和開放包

The exports directive specifies the name of a package to be exported by the current module. For code in other modules, this grants access at compile time and run time to the public and protected types in the package, and the public and protected members of those types (§6.6). It also grants reflective access to those types and members for code in other modules.

exports指令指定了當前模塊要導出的包的名稱。對於其他模塊的代碼來說,這將允許它們在編譯時和運行時訪問包中的public和protected類型,以及這些類型(第6.6節)中的public和protected成員。同樣的,也允許它們反射訪問這些類型和成員。

The opens directive specifies the name of a package to be opened by the current module. For code in other modules, this grants access at run time, but not compile time, to the public and protected types in the package, and the public and protected members of those types. It also grants reflective access to all types in the package, and all their members, for code in other modules.

opens指令指定了當前模塊要開放的包的名稱。對於其他模塊的代碼來說,這將允許它們在運行時(而不是編譯時)訪問包中的public和protected類型,以及這些類型的public和protected成員。同樣的,也允許它們反射訪問包中的所有類型以及類型的所有成員。

It is a compile-time error if the package specified by exports is not declared by a compilation unit associated with the current module (§7.3).

如果由exports指定的包未被與當前模塊關聯的編譯單元(第7.3節)聲明的話,會發生編譯時錯誤。

It is permitted for opens to specify a package which is not declared by a compilation unit associated with the current module. (If the package should happen to be declared by an observable compilation unit associated with another module, the opens directive has no effect on that other module.)

用opens來指定未被與當前模塊關聯的編譯單元所聲明的包是合法的(如果包恰好被其他模塊關聯的可觀察編譯單元聲明瞭,那麼opens指令將不會對那些模塊起作用)。

It is a compile-time error if more than one exports directive in a module declaration specifies the same package name.

如果模塊聲明中存在多個exports指令指定同樣的包名,則會產生編譯時錯誤。

It is a compile-time error if more than one opens directive in a module declaration specifies the same package name.

如果模塊聲明中存在多個opens指令指定同樣的包名,則會產生編譯時錯誤。

It is a compile-time error if an opens directive appears in the declaration of an open module.

如果在開放模塊的聲明中出現opens指令,則會產生編譯時錯誤。

If an exports or opens directive has a to clause, then the directive is qualified; otherwise, it is unqualified. For a qualified directive, the public and protected types in the package, and their public and protected members, are accessible solely to code in the modules specified in the to clause. The modules specified in the to clause are referred to as friends of the current module. For an unqualified directive, these types and their members are accessible to code in any module.

如果exports或者opens指令有to子句,那麼該指令是限定的;否則就是非限定的。對於限定指令來說,包中的public和protected類型以及這些類型的public和protected成員只能被to子句中指定的模塊的代碼所訪問。to子句中指定的模塊被稱爲當前模塊的friends。對於非限定指令來說,任何模塊的代碼都能訪問這些類型和它們的成員。

It is permitted for the to clause of an exports or opens directive to specify a module which is not observable (§7.7.6).

用exports或者opens指令的to子句指定不可觀察(第7.7.6節)的模塊是合法的。

It is a compile-time error if the to clause of a given exports directive specifies the same module name more than once.

如果給定的exports指令的to子句多次指定相同的模塊名,則會產生編譯時錯誤。

It is a compile-time error if the to clause of a given opens directive specifies the same module name more than once.

如果給定的opens指令的to子句多次指定相同的模塊名,則會產生編譯時錯誤。

7.7.3 Service Consumption

7.7.3 服務消費

The uses directive specifies a service for which the current module may discover providers via java.util.ServiceLoader.

uses指令指定當前模塊可以通過java.util.ServiceLoader發現提供者的服務。

The service must be a class type, an interface type, or an annotation type. It is a compile-time error if a uses directive specifies an enum type (§8.9) as the service.

服務必須是類類型、接口類型或者註解類型。如果users指令指定了枚舉類型(第8.9節)作爲服務,則會產生編譯時錯誤。

The service may be declared in the current module or in another module. If the service is not declared in the current module, then the service must be accessible to code in the current module (§6.6), or a compile-time error occurs.

服務可以在當前模塊或者其他模塊中聲明。如果服務不是在當前模塊中聲明,那麼該服務必須可以被當前模塊中的代碼訪問,否則會產生編譯時錯誤。

It is a compile-time error if more than one uses directive in a module declaration specifies the same service.

如果在一個模塊聲明中有多個uses指令指定了相同的服務,則會產生編譯時錯誤。

7.7.4 Service Provision

7.7.4 服務提供

The provides directive specifies a service for which the with clause specifies one or more service providers to java.util.ServiceLoader.

provides指令將爲with子句指定的一個或多個服務提供者指定一個服務給java.util.ServiceLoader。

The service must be a class type, an interface type, or an annotation type. It is a compile-time error if a provides directive specifies an enum type (§8.9) as the service.

服務必須是類類型、接口類型或者註解類型。如果provides指令指定枚舉類型(第8.9節)作爲服務,則會產生編譯時錯誤。

The service may be declared in the current module or in another module. If the service is not declared in the current module, then the service must be accessible to code in the current module (§6.6), or a compile-time error occurs.

服務可以在當前模塊或者其他模塊中聲明。如果服務沒有在當前模塊中聲明,那麼它必須可以被當前模塊(第6.6節)中的代碼訪問,否則會產生編譯時錯誤。

Every service provider must be a class type or an interface type, that is public, and that is top level or nested static, or a compile-time error occurs.

每個服務提供者必須是類類型或者接口類型,它是public的,並且是頂層級別或者是嵌套static的,否則會產生編譯時錯誤。

Every service provider must be declared in the current module, or a compile-time error occurs.

每個服務提供者必須在當前模塊中聲明,否則會產生編譯時錯誤。

If a service provider explicitly declares a public constructor with no formal parameters, or implicitly declares a public default constructor (§8.8.9), then that constructor is called the provider constructor.

如果服務提供者明確聲明瞭一個沒有形式參數的public構造函數,或者隱式聲明瞭一個默認的public構造函數(第8.8.9節),那麼這個構造函數就叫做提供者構造函數。

If a service provider explicitly declares a public static method called provider with no formal parameters, then that method is called the provider method.

如果服務提供者明確聲明瞭一個名爲provider而且沒有形式參數的public static方法,那麼這個方法就叫做提供者方法。

If a service provider has a provider method, then its return type must i) either be declared in the current module, or be declared in another module and be accessible to code in the current module; and ii) be a subtype of the service specified in the provides directive; or a compile-time error occurs.

如果服務提供者有提供者方法,那麼它的返回類型必須:1)是在當前模塊中或者其他模塊中被聲明,而且可以被當前模塊中的代碼訪問;2)是在provides指令中指定的服務的子類型。否則會產生編譯時錯誤。

While a service provider that is specified by a provides directive must be declared in the current module, its provider method may have a return type that is declared in another module. Also, note that when a service provider declares a provider method, the service provider itself need not be a subtype of the service.

雖然由provides指令指定的服務提供者必須在當前模塊中聲明,但是它的提供者方法可能具有在其他模塊中聲明的返回類型。另外注意,當服務提供者聲明瞭提供者方法時,服務提供者本身不一定是服務的子類型。

If a service provider does not have a provider method, then that service provider must have a provider constructor and must be a subtype of the service specified in the provides directive, or a compile-time error occurs.

如果服務提供者沒有提供者方法,那麼該服務提供者必須有提供者構造函數以及必須有在provides指令中指定的服務的子類型,否則會產生編譯時錯誤。

It is a compile-time error if more than one provides directive in a module declaration specifies the same service.

如果在模塊聲明中有多個provides指令指定相同的服務,則會產生編譯時錯誤。

It is a compile-time error if the with clause of a given provides directive specifies the same service provider more than once.

如果給定的provides指令的with子句中多次指定了相同的服務提供者,則會產生編譯時錯誤。

7.7.5 Unnamed Modules

7.7.5 未具名模塊

An observable ordinary compilation unit that the host system does not associate with a named module (§7.3) is associated with an unnamed module.

主機系統不與具名模塊(第7.3節)相關聯的可觀察的普通編譯單元,是與未具名模塊相關聯的。

Unnamed modules are provided by the Java SE Platform in recognition of the fact that programs developed prior to Java SE 9 could not declare named modules. In addition, the reasons for the Java SE Platform providing unnamed packages (§7.4.2) are largely applicable to unnamed modules.

由於認識到在Java SE 9之前開發的程序無法聲明具名模塊,因此由Java SE平臺提供了未具名模塊。另外,Java SE平臺提供了未具名包(第7.4.2節)的原因是爲了適用於未具名模塊。

An implementation of the Java SE Platform must support at least one unnamed module. An implementation may support more than one unnamed module, but is not required to do so. Which ordinary compilation units are associated with each unnamed module is determined by the host system.

Java SE平臺的實現必須至少支持一個未具名模塊。該實現可能支持多個未具名模塊,但不需要這樣做。由主機系統決定哪個普通編譯單元與每個未具名模塊的關聯關係。

The host system may associate ordinary compilation units in a named package with an unnamed module.

主機系統可以將具名包中的普通編譯單元與未具名模塊相關聯。

The rules for unnamed modules are designed to maximize their interoperation with named modules, as follows:

未具名模塊的規則被設計爲最大化與具名模塊的互操作,如下所示:

• An unnamed module reads every observable module (§7.7.6).

• 未具名模塊能夠讀取每個可觀察模塊(第7.7.6節)。

By virtue of the fact that an ordinary compilation unit associated with an unnamed module is observable, the associated unnamed module is observable. Thus, if the implementation of the Java SE Platform supports more than one unnamed module, every
unnamed module is observable; and each unnamed module reads every unnamed module including itself.

由於與未具名模塊相關聯的普通編譯單元是可觀察的,所以相關聯的未具名模塊是可觀察的。因此,如果Java SE平臺的實現支持多個未具名模塊,則每個未具名模塊都是可觀察的; 並且每個未具名的模塊能夠讀取每個未具名的模塊,包括它本身。

However, it is important to realize that the ordinary compilation units of an unnamed module are never visible to a named module (§7.3) because no requires directive can arrange for a named module to read an unnamed module. The Core Reflection API of the Java SE Platform may be used to arrange for a named module to read an unnamed module at run time.

然而,重要的是要認識到未具名模塊的普通編譯單元永遠不可見於具名模塊(第7.3節),因爲沒有requires指令安排具名模塊讀取未具名模塊。Java SE平臺的核心反射API可用於在運行時安排具名模塊讀取未具名模塊。

• An unnamed module exports every package whose ordinary compilation units are associated with that unnamed module.

• 未具名模塊會導出與其相關聯的普通編譯單元的每一個包。

• An unnamed module opens every package whose ordinary compilation units are associated with that unnamed module.

• 未具名模塊會開放與其相關聯的普通編譯單元的每一個包。

7.7.6 Observability of a Module

7.7.6 模塊的可觀察性

A module is observable if at least one of the following is true:

如果模塊是可觀察的,那麼至少以下有一個是正確的:

• A modular compilation unit containing the declaration of the module is observable (§7.3).

• 包含模塊聲明的模塊化編譯單元是可觀察的(第7.3節)。

• An ordinary compilation unit associated with the module is observable.

• 與模塊相關聯的普通編譯單元是可觀察的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章