FileDocCategorySizeDatePackage
InstanceRunner.javaAPI DocExample3027Sun Feb 08 21:34:06 GMT 2004None

InstanceRunner

public class InstanceRunner extends Object implements Runnable
Runs a no-argument method from another class, showing use of Method.invoke().

Fields Summary
private Class
targetClass
private String
methodName
Constructors Summary
public InstanceRunner(Class c, String method)

		targetClass = c;
		methodName = method;
	
Methods Summary
public voidrun()
This run method simply invokes a named method in the given target class.

		try {
			Object o = targetClass.newInstance();
			Method m = targetClass.getMethod(methodName, new Class[0]);
			m.invoke(o, new Object[0]);
		} catch (Exception ex) {
			System.err.println("Caught Exception: " + ex);
		}