Make Java class visible only within the project / app workspace

I am developing an SDK in java and my problem is hiding some java classes / packages, so no third-party application using this sdk is exposed to this class underscore

I know that if all the class objects in sdk were inside the same package, I can assign default / secure access modifiers to the class that I want to hide. However, like a large number of java projects, a java project, such as my sdk, consists of different packages that appropriately group the relevant java class.

This means that if I want to hide / protect a class that is in com.abc, the main root class that the world sees in com.a will not be able to access classes protected in com.abc, etc.

How can I provide a solution for this, and not just dump all the classes in one big package?

Thank.

+4
source share
2 answers

The Java namespace and access modifiers are not hierarchical, even if it looks like a folder namespace structure. Java does have a flat namespace with arbitrary full names (dot notation).

So, if you want to close your library classes and use them in the library at the same time, there is no other way to put them in one package. Maybe it’s best to explain: when you use a class outside the package, this class is part of the API, since every package in Java is a module.

+1
source

factory ​​ . , .

+1

Source: https://habr.com/ru/post/1534784/


All Articles