Are private members really more “secure” in Java?

后端 未结 8 2911
后悔当初
后悔当初 2021-02-19 03:23

Learning Java I was sometimes taught to use the private access modifier so as not to expose \"sensitive information\" to other classes, as if this could open a legi

8条回答
  •  一个人的身影
    2021-02-19 04:00

    Obviously the principles of making everything private where possible only apply if you adhere to the open-closed principle otherwise if people get used to the idea of editing the internals of existing classes instead of extending them they may well change the encapsulation of private member variables be it through making them accessible through mutators and accessors or changing the access modifier.

提交回复
热议问题