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

前端 未结 14 1059
甜味超标
甜味超标 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.

提交回复
热议问题