How to get variable name in Java?
java, reflection
Solution
If `anyVariableName` is a local variable, you can't. If it's a field, use `Class#getField()` or `Class#getDeclaredField()`.
Problem
Possible Duplicate: Java Reflection: How to get the name of a variable? I've found various discussions on this topic but never any satisfying answer.. ``` A anyVariableName = new A(); ``` How can I get the name of the variable `anyVariableName` and get string `"anyVariableName"` as a result? Is this possible in Java?