Doradus
Doradus

Reputation: 1036

Java module glossary

What is the difference between all these terms used in the Java module specification? I can't find a definition of these terms that doesn't circularly reference itself.

The spec makes such statements as this, but I have not yet figured out what these words actually mean:

Specifically, the host system must limit the ordinary compilation units that would otherwise be observable, to only those that are visible to M

(JLS 11 section 7.3 p.183)

Upvotes: 5

Views: 133

Answers (2)

Stephan Herrmann
Stephan Herrmann

Reputation: 8178

First, in JLS terms like visibility may have different meaning when applied to a compilation unit, or a package, or a type.

Some references where terms are defined in JLS:

  • Observable:

    • Compilation unit: §7.3, sentence starting "The host system determines which compilation units are observable".

    • Package: §7.4.3, first paragraph.

    • Intuition: elements that participate in compilation.

  • Visible:

    • Compilation unit: §7.3, sentence starting "The ordinary compilation units that are visible to M" - note that visibility is defined relative to a module

    • Package: §7.4.3, sentence starting "A package is visible to a module M" - again relative to a module.

    • Intuition: elements that are observable from the perspective of a given module considering requires and exports.

  • Accessible:

    • General definition: §6.6

Additionally, the central new notion since JLS 9 is "uniquely visible" (§7.4.3), plus the terms "potentially accessible", "reads" / "read by", "associated with". Historically, JLS 9 made a further distinction between "technically observable" and "really observable", which has been dropped as of JLS 11.

Also, historically (up-to JLS 8), "visible" was used in the definition of shadowing (§6.4.1), but this use has been withdrawn in JLS 9.

Finally note, that some of these notions (explicitly or implicitly) pull in definition from the API in java.lang.module.

I suggest to consider these terms as technical terms, not meant to appeal to the intuition of a broader audience, in part because many definitions in JLS reason about "compilation units", which are not necessary for an intuitive understanding. For a comparison of a possible intuitive understanding vs. the JLS-based understand please see Slide #20 of JDT embraces Java™ 9 - An insiders' view.

Upvotes: 5

user10750893
user10750893

Reputation: 1

java.util.Observable is unrelated to the module system.

In the JLS, the hierarchy goes bottom up, as follows: 1. Observable: The totality of compilation units that a compiler knows about. 2. Visible: All the compilation units in those modules that are read by the module whose code is currently being compiled. What each module reads is driven by requires directives. Visibility drives what packages and types are in scope, and affects accessibility. 3. Accessible: The public types in those packages that are exported by one module to another module, as long as packages in the first module are visible to the other module.

Upvotes: 0

Related Questions