Java 9 sub-packages split across modules

2019-02-20 20:17发布

问题:

In Java 9, can I split sub-packages across modules? For example, can I have com.example.foo in one module and com.example.foo.bar in another module?

This seems like a simple question, but for some reason I'm not able to find a direct answer after some searching. An authoritative reference would be appreciated.

I assume I can have sibling sub-packages in different modules, e.g. com.example.foo and com.example.other.

回答1:

There's no such thing as a "sub-package". my.package and my.package.sub have nothing more in common than any two random packages: they just have similar names. See this answer which starts

In reality there is no such thing as a sub-package in Java

That being the case, yes you can include them in different modules.