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