nameof equivalent in Java

前端 未结 4 530
生来不讨喜
生来不讨喜 2020-12-16 09:35

C# 6.0 introduced the nameof() operator, that returns a string representing the name of any class / function / method / local-variable / property identifier put

4条回答
  •  猫巷女王i
    2020-12-16 10:31

    Sadly, there is nothing like this. I had been looking for this functionality a while back and the answer seemed to be that generally speaking, this stuff does not exist.

    See Get name of a field

    You could, of course, annotate your field with a "Named" annotation to essentially accomplish this goal for your own classes. There's a large variety of frameworks that depend upon similar concepts, actually. Even so, this isn't automatic.

提交回复
热议问题