Hiding classes in a jar file

前端 未结 8 1601
渐次进展
渐次进展 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条回答
  •  萌比男神i
    2020-12-06 02:37

    I'm understanding you're not looking to hide the actual classes, just prevent their construction outside a factory class. This I think can be quite easily achieved by using package private (default) visibility in the class constructors. The only limitation is that you'll need to have the classes and the factory in the same package so in a medium to large codebase things may get unnecessarily complex.

提交回复
热议问题