Created
July 30, 2020 15:40
-
-
Save zhusaidong/2f98d81fdd32cd57e0a2a86c2c03ef7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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