Skip to content

Instantly share code, notes, and snippets.

@gnrfan
Created May 31, 2011 00:00
Show Gist options
  • Save gnrfan/999651 to your computer and use it in GitHub Desktop.
Save gnrfan/999651 to your computer and use it in GitHub Desktop.
Java Snippet: Dynamically access an static object property using the Reflection API
import java.lang.reflect.Field;
final class ContainerClass {
public static final String some_key = "Hello World";
}
public class ReflectionStaticMemberTest {
public static void main(String args[]) throws Exception {
Field prop = ContainerClass.class.getDeclaredField("some_key");
System.out.println(prop.get(null));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment