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

前端 未结 6 2283
南方客
南方客 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 18:59

    requires describes the process of resolution on how modules are dependent on each other.

    Quoting line

    A 'requires' directive (irrespective of 'transitive') expresses that one module depends on some other module. The effect of the 'transitive' modifier is to cause additional modules to also depend on the other module. If module M 'requires transitive N', then not only does M depend on N, but any module that depends on M also depends on N. This allows M to be refactored so that some or all of its content can be moved to a new module N without breaking modules that have a 'requires M' directive.

    In short :

    requires - M module depends on some other module N.

    requires transitive - additional modules implicitly depends on the other module. Eg:, If M module depends on N, and other module P depends on M. Then, it is implicitly dependent on N as well.

提交回复
热议问题