import java.lang.reflect.*;
public class TestParty{
public static void main(String[] args){
Class c;
Method m;
Constructor con;
Object pt = null;
Object[] oa = null; // we don't use oa and ca in this
Class[] ca = null; // program except as dummy arguments.
try{
// run through list of class names
// as provided on the command line
int i=0;
while (i < args.length){
// find and load the class dynamically
c = Class.forName(args[i]);
// and locate the method we want
m = c.getMethod("partyPiece",ca);
// create an instance
con = c.getConstructor(ca);
pt = con.newInstance(oa);
// see what happens if we invoke the method
// NB the partyPiece() method will return a string
System.out.println(i+" "+m.invoke(pt,oa));
// bump loop
i++;
}
}
catch(Exception e){System.out.println("ERROR "+e.getMessage());}
}
}
|