FileDocCategorySizeDatePackage
MethodInfoDemo.javaAPI DocExample2413Sun Dec 14 22:47:40 GMT 2003oreilly.hcj.reflection

MethodInfoDemo

public class MethodInfoDemo extends Object
Demonstrates how to get simple method information.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.3 $

Fields Summary
Constructors Summary
Methods Summary
public static voidemptyStrings(java.lang.Object obj)
__UNDOCUMENTED__

param
obj __UNDOCUMENTED__
throws
IllegalAccessException __UNDOCUMENTED__
throws
InvocationTargetException __UNDOCUMENTED__

		final String PREFIX = "set";  //$NON-NLS-1$
		Method[] methods = obj.getClass()
			                  .getMethods();
		for (int idx = 0; idx < methods.length; idx++) {
			if (methods[idx].getName()
			                .startsWith(PREFIX)) {
				if (methods[idx].getParameterTypes()[0] == String.class) {
					methods[idx].invoke(obj, new Object[] { new String() });
				}
			}
		}
	
public static voidmain(java.lang.String[] args)
Demo method.

param
args Command line arguments.

		Person p = new Person();
		p.setFirstName("Robert");
		p.setLastName("Simmons");
		p.setGender(Gender.MALE);
		p.setTaxID("123abc456");

		printMethodInfo(p);

		try {
			System.out.println("==> " + p.getFirstName());
			emptyStrings(p);
			System.out.println("==> " + p.getFirstName());
		} catch (final Exception ex) {
			ex.printStackTrace();
		}
	
public static voidprintMethodInfo(java.lang.Object obj)
__UNDOCUMENTED__

param
obj __UNDOCUMENTED__

		Class type = obj.getClass();
		final Method[] methods = type.getMethods();
		for (int idx = 0; idx < methods.length; idx++) {
			System.out.println(methods[idx]);
		}