Pros and cons of package private classes in Java?

前端 未结 8 1821
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 05:05

I am learning Java recently, and I came across the notion of package-private classes, which is the default if we don\'t specify anything. But then I realized:

8条回答
  •  星月不相逢
    2020-11-27 05:16

    One nice thing about package-private is that you can use it to give access to methods you would otherwise consider private to unit test classes. The downside of course being that other classes in the package could call it when they really shouldn't.

提交回复
热议问题