Search code examples
javajava-9java-platform-module-systemjava-module

What is the difference between ResolvedModule, Module and Observable Module


The documentation for each of these states following:

ResolvedModule

A module in a graph of resolved modules. ResolvedModule defines the configuration method to get the configuration that the resolved module is in. It defines the reference method to get the reference to the module's content.

Module

Represents a run-time module, either named or unnamed.

Q:- When does these two differ, is it at the compile and the run time or is it just different representation of a module?

On the other hand, the module-path defines

The modules built-in to the compile-time or run-time environment, together with those defined by artifacts on the module path, are collectively referred to as the universe of observable modules.

Q:- Are all these related? Could someone please draw an example of how and at what time to explain the concept?


Solution

  • Start with the java.lang.module package description where resolution is specified and you will learn about readability and readability graphs.

    Then look at the Configuration class as a Configuration object encapsulates a readability graph. Each vertex in the graph is represented by a ResolvedModule.

    Once you have a Configuration then you can think of instantiating it as a graph of modules in the Java Virtual Machine. This will lead to you the java.lang.ModuleLayer API.

    I think part of the question is asking if there is a 1-1 relationship between the model world ResolvedModule and the run-time Module. Usually yes, but there is nothing to stop you instantiating a Configuration multiple times which will result in several module layers created from the same configuration.

    It's probably too much to be thinking about now, best to digest the design and API before going there.