3

I have learn that in order to use any other exported module, we need to specify that module as a requires:

module mymodule{
       requires othermodule.xyz;
}

When othermodule uses on thirdmodule and mymodule needs that as well, othermodule should define transitive dependency like this:

module othermodule {
       requires transitive thirdmodule  
}

However, I have seen many sites that use the public keyword for this situation:

module othermodule {
       requires public  thirdmodule  
}

What is the difference there is between the two forms; i.e. requires public and requires transitive?

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Niraj Sonawane
  • 10,225
  • 10
  • 75
  • 104
  • 3
    Did you mean `requires static`? There is no such thing as `requires public` – ZhekaKozlov Nov 20 '17 at 13:31
  • I have edited the question to remove the subquestions that are duplicate. – Stephen C Nov 20 '17 at 16:02
  • 2
    @StephenC I am not sure what the consensus on Meta for such edits would be which could change the meaning altogether. I would still vote to close this question as no/research or no debugging attempts though. – Naman Nov 20 '17 at 17:25
  • @nullpointer - If you want to know what the consensus is, ask on meta. – Stephen C Mar 06 '18 at 03:08

1 Answers1

7

The requires public was part of an earlier version of the modules sub-language that was revised before the release of Java 9. According to the Java 9 JLS, the public keyword is not allowed in a ModuleDirective: see JLS 7.7.

The sites that use the requires public syntax are out of date / incorrect. This is acknowledged in the following, for example:

Basically requires public is outdated (now invalid) syntax, and requires transitive is its replacement.

Naman
  • 27,789
  • 26
  • 218
  • 353
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216