728x90
반응형


import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;


public class Test {
    public Test() {
    }

    public String getTestString(String test) {
        return test;
    }

    public String execute() throws SecurityException, NoSuchMethodException

                                                , InvocationTargetException, IllegalArgumentException,

                                                IllegalAccessException {
        Class[] types = {String.class};
        Object[] args = {"박한나입니다."};

       

        //getTestString함수를 호출

        Method method = this.getClass().getMethod("getTestString", types);          

        String test = (String)method.invoke(this, args);
        
        return test;
    }

 

 

    /**
     * main
     *
     * @param args String[]
     */
    public static void main(String[] args) {

 

        try {
           Test test = new Test();
           System.out.println(test.execute());

        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }


    }


728x90
반응형

+ Recent posts