Dosen't Reflection API break the very purpose of Data encapsulation?

前端 未结 4 464
无人共我
无人共我 2021-01-05 01:31

Very recently I came across the Reflection API and to my surprise we can access and even alter the private variables.I tried the following code

import java.l         


        
4条回答
  •  走了就别回头了
    2021-01-05 01:48

    Yes, It does violate OO concepts. However it does not break any java security model. It can be controlled by java security manager if necessary. Java reflection itself is an useful thing. It is used in Annotations and IOCs which are very useful concepts with ability to handle classes during runtime.

提交回复
热议问题