Are private methods really safe?

后端 未结 7 1676
旧巷少年郎
旧巷少年郎 2021-01-30 15:26

In Java the private access modifier consider as safe since it is not visible outside of the class. Then outside world doesn\'t know about that method either.

7条回答
  •  渐次进展
    2021-01-30 16:00

    By saying 'safe', you are protecting you or other developers, which are using your API to not harm the object by calling your private method. But if you or they really need to call this method, they can do it with Reflection.

提交回复
热议问题