FileDocCategorySizeDatePackage
FindField.javaAPI DocExample980Sat Apr 28 10:22:40 BST 2001None

FindField

public class FindField extends Object
This class shows using Reflection to get a field from another class.

Fields Summary
Constructors Summary
Methods Summary
intintFieldValue(java.lang.Object o, java.lang.String name)

		Class c = o.getClass();
		Field fld = c.getField(name);
		int value = fld.getInt(o);
		return value;
	
public static voidmain(java.lang.String[] unused)


		// Create instance of FindField
		FindField gf = new FindField();

		// Create instance of target class (YearHolder defined below).
		Object o = new YearHolder();

		// Use gf to extract a field from o.
		System.out.println("The value of 'currentYear' is: " +
			gf.intFieldValue(o, "currentYear"));