java-package

How to organize code logically into package while preserving encapsulation

旧城冷巷雨未停 提交于 2021-02-10 12:23:50
问题 This is a conceptual question. I usually organize code in packages logically. E.g.: math operation goes in my.package.math or business logic goes into my.package.business and so on. In these days I have a doubt that I want to share about a constraint imposed by the package visibility in java. Let me show some code to explain better my case: I have the following package structure: +-- org.example +-- greetings | +-- RandomGreetings +-- GreetingsService | +-- Main and the following code:

Can one Java module export a package whose name is a subpackage of a package from another module? [duplicate]

别来无恙 提交于 2019-12-22 18:49:13
问题 This question already has an answer here : Java 9 sub-packages split across modules (1 answer) Closed 11 months ago . So I know that, in Java 9 modules (Project Jigsaw), split packages are not allowed. That is, the following modules couldn't both export a package with the same name and also be used at the same time at run time: Module 1 module com.example.foo { exports com.example.foo; } Module 2 module com.example.foo { exports com.example.foo; } Not allowed (or, at least, they can't run at

Can one Java module export a package whose name is a subpackage of a package from another module? [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-06 11:10:33
This question already has an answer here : Java 9 sub-packages split across modules (1 answer) Closed 10 months ago . So I know that, in Java 9 modules (Project Jigsaw), split packages are not allowed. That is, the following modules couldn't both export a package with the same name and also be used at the same time at run time: Module 1 module com.example.foo { exports com.example.foo; } Module 2 module com.example.foo { exports com.example.foo; } Not allowed (or, at least, they can't run at the same time). But what isn't clear to me is how subpackages come in to play. If one module exports