Does reflection breaks the idea of private methods, because private methods can be access outside of the class?

前端 未结 14 978
甜味超标
甜味超标 2020-11-28 08:06

Does reflection break the idea of private methods? Because private methods can be accessed from outside of the class? (Maybe I don\'t understand the meaning of reflection or

相关标签:
14条回答
  • 2020-11-28 08:52

    Yes, Reflection could be used to violate encapsulation and even cause incorrect behavior. Keep in mind that the assembly needs to be trusted to perform reflection, so there are still some protections in place.

    0 讨论(0)
  • 2020-11-28 08:57

    It does, as other already stated.

    However, I remember that in Java there can be a security manager active, that could prevent you from accessing any private methods, even with reflection, if you don't have the rights to do so. If you run your local JVM, such a manager is usually not active.

    0 讨论(0)
提交回复
热议问题