Use-cases for reflection

后端 未结 9 2145
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 20:34

Recently I was talking to a co-worker about C++ and lamented that there was no way to take a string with the name of a class field and extract the field with that name; in o

9条回答
  •  一向
    一向 (楼主)
    2020-12-08 21:01

    Writing dispatchers. Twisted uses python's reflective capabilities to dispatch XML-RPC and SOAP calls. RMI uses Java's reflection api for dispatch.

    Command line parsing. Building up a config object based on the command line parameters that are passed in.

    When writing unit tests, it can be helpful to use reflection, though mostly I've used this to bypass access modifiers (Java).

提交回复
热议问题