#001 public class Test {
#002 public double d;
#003
#004 public static void main(String args[])
#005 {
#006 Class c = Class.forName("Test");
#007 Field f = c.getField("d"); //指定field 名称
#008 Test obj = new Test();
#009 System.out.println("d= " + (Double)f.get(obj));
#010 f.set(obj, 12.34);
#011 System.out.println("d= " + obj.d);
#012 }
#013 } 图9:动态变更field 内容
l "Take an in-depth look at the Java Reflection API -- Learn about the new Java 1.1 tools forfinding out information about classes", by Chuck McManis。此篇文章所附程序代码是本文示例程序的主要依据(本文示例程序示范了更多Reflection APIs,并采用JDK1.5 新式的for-loop 写法)。
l "Take a look inside Java classes -- Learn to deduce properties of a Java class from inside aJava program", by Chuck McManis。
l "The basics of Java class loaders -- The fundamentals of this key component of the Javaarchitecture", by Chuck McManis。
l 《The Java Tutorial Continued》, Sun microsystems. Lesson58-61, "Reflection".