You could do something like this:
import java.lang.reflect.*;
public class Foo {
public static int one = 1;
public static int two = 2;
public static int three = 3;
public static void magicMethod( Class clz ) throws Exception {
Field[] fields = clz.getFields();
System.out.println(""+fields);
for( Field field : fields ) {
int modifiers = field.getModifiers();
if( ! Modifier.isStatic(modifiers) )
continue;
System.out.println("" + field.get(null));
}
}
public static void main(String[] args) throws Exception {
Foo.magicMethod( Foo.class );
}}
It's important to note, however, that the fields have to be public for this to work. It's not exactly what you asked, but it should be close enough that you should be able to make it work for what you need. Obviously this doesn't do any kind of error handling or anything so you should make sure that you handle any errors or exceptions in your real application.