What is the use of package level protection in java?

前端 未结 15 1061
时光说笑
时光说笑 2020-12-05 14:28

I know how package level protection in java works. I read a lot of code (including lots of open source stuff) and no-one seem to be using it. The whole protection l

15条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 14:52

    In general, Default/Package protection can be used to to make "Public" classes and variables more restricted.

    You only export a few methods from your class (if you're a good programmer) by tagging them public while keeping as much as possible private.

    Package protection allows you to only export a few classes from your package, keeping the rest private.

    In theory it's a great idea, in practice you almost never see it.

提交回复
热议问题