Programming/Java
Reflection을 이용해 class variable name 얻기
halatha
2011. 3. 31. 06:28
// http://stackoverflow.com/questions/744226/java-reflection-how-to-get-the-name-of-a-variable import java.lang.reflect.Field; public class TestReflect { public int i = 5; public Integer test = 5; public String omghi = "der"; public static String testStatic = "THIS IS STATIC"; public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException { TestReflect t = new TestReflect(); for(Field f : t.getClass().getFields()) { System.out.println(f.getGenericType() + "\t" + f.getName() + " = " + f.get(t)); } } }