Skip to content

Instantly share code, notes, and snippets.

@zhusaidong
Created July 30, 2020 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhusaidong/2f98d81fdd32cd57e0a2a86c2c03ef7a to your computer and use it in GitHub Desktop.
Save zhusaidong/2f98d81fdd32cd57e0a2a86c2c03ef7a to your computer and use it in GitHub Desktop.
import java.lang.reflect.*;
public class AA{
public static final String FOO = "foo";
public static final String BAR = "bar";
public static void main(String[] args){
new AA().printAllProps(AA.class);
}
public void printAllProps(Class c){
Field[] fields = null;
fields = c.getDeclaredFields();
for(Field field : fields){
try{
System.out.println(String.format("name: %s value: %s", field.getName(), String.valueOf(field.get(c))));
}
catch(IllegalAccessException e){
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment