ImportJava. Lang. Reflect .*;
Public class testm
{
Public static void main (string [] ARGs)
{
Try {
Testm T = new testm ();
Class C = T. getclass ();
Class [] cargs = new class [2];
String [] realargs = {"AA", "BB "};
Cargs [0] = realargs. getclass ();
Integer in = new INTEGER (2 );
Cargs [1] = in. getclass ();
Method M = C. getmethod ("test", cargs); // The test method is called and the return value is the method variable.
Object [] inargs = new object [2];
Inargs [0] = readargs; // Ha, here the error of wingzhang should be realargs.
Inargs [1] = in;
M.Invoke(T, inargs );
} Catch (exception e) {system. Out. println (E );}
}
Public void test (string [] STR, integer stri)
{
For (Int J = 0; j <Str. length; j ++)
System. Out. println (STR [J]);
System. Out. println (stri. intvalue ());
}
}
//
Invoke(Object proxy, method, object [] ARGs)
Process method calls on the proxy instance and return results.
//
Proxy-proxy instance on which the method is called
Method-the Method Instance corresponding to the interface method called on the proxy instance. The method object Declaration class will be the interface in which the method is declared. This interface can be a superinterface of the proxy interface on which the proxy class inherits the method.
ARGs-an array of objects that contain the parameter values of method calls on the proxy instance. If the interface method does not use a parameter, It is null. Parameters of the basic type are encapsulated in the appropriate basic package class (suchJava. Lang. Integer orJava. Lang. Boolean.