Are private methods really safe?

后端 未结 7 1534
旧巷少年郎
旧巷少年郎 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:15

    With facility, there comes responsibility. There are thing's you can't do, & things you can do but you shouldn't do.

    Private modifier is provided/used as/in the most restricted manner. Members which should not be visible outside the class shall be defined as private. But this can be broken with Reflection as we see. But this does not mean that you should not use private - or they are unsafe. It is about you shall use things judiciously or in constructive manner (like reflection).

提交回复
热议问题