Using Java Reflection, is it possible to get the name of a local variable? For example, if I have this:
Foo b = new Foo(); Foo a = new Foo(); Foo r = new Fo
You can do like this:
Field[] fields = YourClass.class.getDeclaredFields(); //gives no of fields System.out.println(fields.length); for (Field field : fields) { //gives the names of the fields System.out.println(field.getName()); }