¼Ò¼³ java.lang ¼Ò½ºÄڵ堠Reflection  ¸Å°³º¯¼ö°¡Àִ¸޼­µåÈ£Ãâ  

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

MethodInvoke1.java

import java.awt.*;
import 
java.lang.reflect.*;
public class 
MethodInvoke1 {
   
public static void 
main(String[] arg)
   
throws 
ClassNotFoundException, NoSuchFieldException, IllegalAccessException,
   NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    Class c = String.
class
;
    Class[] parameterTypes = 
new Class[] {int.class, int.class
};
    Method m = c.getMethod(
"substring"
, parameterTypes);
    Object[] parameters = 
new Object[] {new Integer(6), new Integer(11
)};
    String s = 
"Hello World"
;
    Object result = m.invoke(s, parameters);
    System.out.println(result.toString());
   }
}

C:\JavaExample\11>javac MethodInvoke.java
C:\JavaExample\11>java MethodInvoke
World

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



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