Hiding classes in a jar file

前端 未结 8 1609
渐次进展
渐次进展 2020-12-06 02:20

Is it really impossible to hide some classes in a jar file?

I wanted not to allow direct instantiation of the classes to keep it more flexible. Only the factory (or

8条回答
  •  日久生厌
    2020-12-06 02:59

    I think you will have either compiler failure or warning if your public factory method try to return something which is "hidden".

    No, you can not hide a public class without reimplementing your own ClassLoader or using OSGi or anything similar.

    What you can do is to separate interface api from the implementation, e.g. have one project which contains only the interfaces and another porject which contains the implmentations. However, you still cannot hide the implementation classes.

提交回复
热议问题