Java 9: Possible to have 2 modules with same name on module path

后端 未结 2 1147
一生所求
一生所求 2020-12-30 09:42

Is it possible to have 2 modules with the exact same name (but with slightly different contents) on the module path?

As far as I can tell, the Java 9 compiler does n

2条回答
  •  既然无缘
    2020-12-30 10:31

    JEP 261 of the module system describes the module path as follows:

    A module path is a sequence, each element of which is either a module definition or a directory containing module definitions. Each module definition is either

    • A module artifact, i.e., a modular JAR file or a JMOD file containing a compiled module definition, or else

    • An exploded-module directory whose name is, by convention, the module's name and whose content is an "exploded" directory tree corresponding to a package hierarchy.

    It then describes the module resolution mechanism:

    When searching a module path for a module of a particular name, the module system takes the first definition of a module of that name. Version strings, if present, are ignored; if an element of a module path contains definitions of multiple modules with the same name then resolution fails and the compiler, linker, or virtual machine will report an error and exit. It is the responsibility of build tools and container applications to configure module paths so as to avoid version conflicts; it is not a goal of the module system to address the version-selection problem.

    As explained, it means that the compiler will complain only if two modules with the same name exist in the same directory.

提交回复
热议问题