¼Ò¼³ java.lang ¼Ò½ºÄڵ堠Reflection  ¸Å°³º¯¼ö°¡¾ø´Â¸Þ¼­µåÈ£Ãâ  

¸Å°³º¯¼ö°¡ ¾ø´Â ¸Þ¼­µå È£Ãâ

MethodInvoke2.java

import java.awt.*;
import 
java.lang.reflect.*;
public class 
MethodInvoke2 {
   
public static void 
main(String[] arg)
   
throws 
ClassNotFoundException, NoSuchFieldException, IllegalAccessException,
   NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Class c = String.
class
;
    Method m = c.getMethod(
"length"null
);
    String s = 
"Hello World"
;
    Object result = m.invoke(s, 
null
);
     System.out.println(result.toString());
   }
}

C:\JavaExample\11>javac MethodInvoke2.java
C:\JavaExample\11>java MethodInvoke2
11

È£ÃâÇϰíÀÚÇÏ´Â ¸Þ¼­µå¸¦ ¾ò¾î³½ ´ÙÀ½, getMethod()¸Þ¼­µåÀÇ ¸Å°³º¯¼ö ÀÚ¸®¿¡ null°ªÀ» ÇÒ´çÇÏ¿© ¸Þ¼­µå¸¦ È£Ãâ



jabookÀúÀÚ¸íÇÔ
Á¦¸ñ:¼Ò¼³°°Àº¹Ì´ÏÄÚµå
ÀÛ¼ºÀÚ:Àںϸâ¹ö ÇÑâÇå