4

please anyone explain me module descriptor file allowed import Why?
what is the used of import statement in module descriptor file.

import java.util.*;

module superman {
}
Naman
  • 27,789
  • 26
  • 218
  • 353
Ng Sharma
  • 2,072
  • 8
  • 27
  • 49

1 Answers1

5

One use would be if you were using the provides directive:

module superman {
    provides com.github.me.superhero.Superhero with com.github.me.superhero.Batman;
    provides com.github.me.superhero.Superhero with com.github.me.superhero.IronMan;
}

Using an import would look like:

import com.github.me.superhero.*;

module superman {
    provides Superhero with Batman;
    provides Superhero with IronMan;
}
Jacob G.
  • 28,856
  • 5
  • 62
  • 116
  • 3
    [§7.3 Compilation Units](https://docs.oracle.com/javase/specs/jls/se13/html/jls-7.html#jls-7.3) of the JLS would seem to support this answer: "A _modular compilation unit_ consists of a `module` declaration (§7.7), optionally preceded by `import` declarations. The `import` declarations allow types from packages in this module and other modules, as well as `static` members of types, to be referred to using their simple names within the `module` declaration". Though interestingly I can't find anything in _§7.7 Module Declarations_ (including subsections) about import statements. – Slaw Feb 18 '20 at 02:01
  • Also from [compilation unit](https://docs.oracle.com/javase/specs/jls/se13/html/jls-7.html#jls-7.3) => `ModularCompilationUnit: {ImportDeclaration} ModuleDeclaration` – Naman Feb 18 '20 at 05:31