JAVA Reflection??????????
???????????? ???????[ 2014/7/4 13:44:17 ] ??????????????? java
????Java.lang.reflect.Constructor
????Class[] getParameterTypes()
????????????????????????????Class????????
????getReturnType()
????????????????????????????Class????
????int getModifiers()
???????????????????????????????????Class????????
????Class getDeclaringClass()
??????????????????????ж????????????????????Class????
????????????????????
??????????????????????new?????????????new?????????????????????????New??????????δ????????????????????????????????ɡ?????Spring??DI??
???????????ι??????????
????Class.newInstance()
????Class.getConstructor(new Class[]{}).newInstance(new Object[]{})
????????????ι??????????
????Clazz.getConstructor(Class<?> ...ParameterType).newInstance(Object ...initargs)
??????????????
import java.lang.reflect.*;
public class DumpMethods {
public static void main(String args[]) throws Exception{
//???????????????в??????????
Class classType = Class.forName(args[0]);
//?????????з???
Method methods[] = classType.getDeclaredMethods();
for(int i = 0; i < methods.length; i++)
System.out.println(methods[i].toString());
}
}
|
????java DumpMethods java.util.Stack
public synchronized java.lang.Object java.util.Stack.pop()
public java.lang.Object java.util.Stack.push(java.lang.Object)
public boolean java.util.Stack.empty()
public synchronized java.lang.Object java.util.Stack.peek()
public synchronized int java.util.Stack.search(java.lang.Object)
|
???????÷????????÷???
????getMethod??invoke??????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11