What's the difference between requires and requires transitive statements in Java 9?

前端 未结 6 2284
南方客
南方客 2020-12-07 18:20

What\'s the difference between requires and requires transitive module statements in module declaration?

For exam

6条回答
  •  长情又很酷
    2020-12-07 19:15

    The Java Language Specification for Java 9 explains it in very simple terms. From the section on Module Dependences:

    The requires directive specifies the name of a module on which the current module has a dependence.

    ...

    The requires keyword may be followed by the modifier transitive. This causes any module which requires the current module to have an implicitly declared dependence on the module specified by the requires transitive directive.

    In other words:

    • if module X requires module Y,
    • and module Y requires transitive module Z,
    • then module X also (implicitly) requires module Z.

提交回复
热议问题