Created
May 31, 2011 00:00
-
-
Save gnrfan/999651 to your computer and use it in GitHub Desktop.
Java Snippet: Dynamically access an static object property using the Reflection API
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.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