What exactly is Reflection and when is it a good approach?

前端 未结 11 1719
天命终不由人
天命终不由人 2020-12-25 14:58

What exactly is Reflection? I read the Wikipedia article on this subject and I understand that it is a kind of meta-programming, where the program can modify itself at run-

11条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-25 15:14

    In Java it is basically a way to instantiate a class without knowing about it before hand. Say you want the user to be able to change a configuration file by adding the class they want your program to use (say you have numerous implementations of some interface). With reflection you can create an object based on just it's name, method signature, etc. . . and then cast it to your interface.

提交回复
热议问题