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

前端 未结 14 1093
甜味超标
甜味超标 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:49

    I think this is a matter of opinion, but if you are using reflection to get around the encapsulation put in place by a developer on a class, then you are defeating the purpose.

    So, to answer your question, it breaks the idea of encapsulation (or information hiding), which simply states that private properties/methods are private so they cant be mucked with outside the class.

提交回复
热议问题