Nontrivial:
Generic classes can be defined by a public set of interfaces. The actual implementation must be loaded explicitly through Classloader . After that, simply apply the Java security management mechanisms to control access to the implementation classes. Anyone can see that the interfaces and access to the actual implementation will be limited by your SDK.
(The importance of the above is what every web application server should do. Do you think that Tomcat prevents you from accessing other "public" application classes?)
edit: the note above is the execution mechanism. There are also static (post) compilation approaches. For example, APT may be effective. Naturally, I am not referring to the restructuring of your package (in the OP) and only to how to provide access to the general approach. But they are a bit “hacked” - the mechanism for loading classes is canonical, and imo is more correct.
source share