Skip to content

Instantly share code, notes, and snippets.

@pato
Last active January 2, 2016 11:09
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 pato/8294889 to your computer and use it in GitHub Desktop.
Save pato/8294889 to your computer and use it in GitHub Desktop.
Example of getting variable names in java
import java.lang.reflect.Field;
public class name {
public int myint = 5;
public Integer myInteger = new Integer(44);
public String pato = "Lankenau";
public boolean mybool = false;
public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {
name t = new name();
for(Field f : t.getClass().getFields()) {
System.out.println(f.getGenericType() +" "+f.getName() + " = " + f.get(t));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment