-1

Let's say I have 2 modules:

  • module1 has the package package1

  • module2 has package2, package3 and package4

I want package1 to be visible to only package2 in module2. not to any other packages (package3 or package4) in module2.

Is this possible using module-info.java?

ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
James
  • 441
  • 2
  • 6
  • 9
  • BTW modules aside, you can't do it in one module itself. It's either package private or public. – Mordechai Mar 18 '18 at 14:04
  • I am wondering what exactly is your use case without the JPMS in play as well? Not able to understand what you desire here. – Naman Mar 18 '18 at 14:53

1 Answers1

5

No, this is not possible. You can only export a package to the whole module:

module module1 {
    exports package1 to module2;
}
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155
  • 1
    Would be useful to quote the JLS to support that. https://docs.oracle.com/javase/specs/jls/se9/html/jls-7.html#jls-7.7 – Naman Mar 18 '18 at 16:48