¸Å°³º¯¼ö°¡ ÀÖ´Â ¸Þ¼µå È£Ãâ
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ÀúÀÚ¸íÇÔ |
Á¦¸ñ:¼Ò¼³°°Àº¹Ì´ÏÄÚµå ÀÛ¼ºÀÚ:Àںϸâ¹ö ÇÑâÇå |