Java: What scenarios call for the use of reflection?

前端 未结 7 1141
无人共我
无人共我 2020-12-29 10:42

So from reading some of the articles, the message i got out of it was being able to modify fields and set values to classes in real time without recompiling.

so is i

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 11:16

    Reflection is also useful in cases where configuration is required to string things together. For example, in an application I wrote I have a @Report("debits") annotation that is simply added to methods that generate reports. Then, in the XML configuration a user can simply add:

    
    

    This minimizes boiler plate code from mapping the XML code to the actual method, since reflection can discover the report methods and make it available directly.

提交回复
热议问题