Let's start with a brief introduction to two meta-annotations:
@retention is () The parameter action time in parentheses compile, run, source code
@target () parentheses within the parameter scope variable, method ....
Get Class object
Class clazz = Class.forName ("Cn.ph.test.UserDao");
Get Object methods
Method[] mds = Clazz.getmethods ();
Traverse
for (Method Md:mds) {
/**
* @MyTest. Class Note decoding objects
*invake (Object Obj,object...args)
*/
if (Md.isannotationpresent (Mytest.class)) {
If there is a custom mytest annotation on the current method, execute, otherwise ignore
Md.invoke (New Userdao ());//class corresponding to the method
}
/*
GetMethod The first parameter is the method name, the second parameter is the parameter type of the method (multiple, separated),
method = Clazz.getmethod ("Test", String.class);
The Invoke (Object Obj,object args[]) method of the methods class must be an object for the parameter to be received.
If the parameter is a base type of data, it must be converted to an object of the appropriate wrapper type. The return value of the Invoke () method is always the object,
If the return type of the method that is actually called is the base type data, then the Invoke () method converts it to an object of the corresponding wrapper type.
and return it to
String s = "AA";
Method.invoke (M, (Object) s);//error time, parameter remember strong turn Object
*/
}
Invoke method for Java reflection