Reflection Get Variables in Method

后端 未结 2 779
逝去的感伤
逝去的感伤 2020-12-19 10:04

How can i get varibles used in Method which then I will write their values on Console ?

2条回答
  •  被撕碎了的回忆
    2020-12-19 11:04

    You cannot. Reflection does not extend to reading the values of method variables. It only handles the declaration metadata of variables. And even then, the compiler may have removed the variable you thought you declared. Reflection allows full access to fields (instance / static type variables), but not method variables.

    There are tricks you can use like lambda expressions, but this changes their form (from method variables into instance fields).

提交回复
热议问题