Why do we need to use private field if we can still ecsess it with the reflection API? I know for what private is for but reflection contrary the private field.
Asked
Active
Viewed 36 times
0
-
4Because `private` is not a security mechanism. It is a primarily mechanism for limiting unwanted coupling between classes. (And sometimes, you need that coupling *despite* the original class designer's intentions ... hence the reflective solution.) – Stephen C Aug 03 '18 at 02:15
-
`private` is (in fact, all access modifiers are) not just a way to control how people interact with your object, but it is also a way to _define_ the object and what it intends to be used for. – ryvantage Aug 03 '18 at 16:55