this is not realistic in Java 6 unless you are using OSGI, which I assume you are not using. what I usually do to hide classes is to use classes that are compatible with packages for implementations - but you still have to expose some classes if you are implementation classes that live in a separate package.
:
package com.example;
public class Service { } Suppose an API class uses ServiceImpl as an implementation
now, if ServiceImpl lives in one package, you can remove its public class modifier and it will not be available outside the package ...
if it lives in another package (your case), it should be publicly available:
package com.example.impl;
public class ServiceImpl { }
but all implementation details (related classes that it uses) from the same package should not be publicly available!
kares Dec 08 2018-10-12 14:52
source share