| 6 | |
| 7 | public class MethodInfo { |
| 8 | public static void main(String[] args) throws Exception{ |
| 9 | |
| 10 | Class clazz = Class.forName("com.fastcampus.ch2.YoilTeller"); |
| 11 | Object obj = clazz.newInstance(); |
| 12 | |
| 13 | Method[] methodArr = clazz.getDeclaredMethods(); |
| 14 | |
| 15 | for(Method m : methodArr) { |
| 16 | String name = m.getName(); |
| 17 | Parameter[] paramArr = m.getParameters(); |
| 18 | // Class[] paramTypeArr = m.getParameterTypes(); |
| 19 | Class returnType = m.getReturnType(); |
| 20 | |
| 21 | StringJoiner paramList = new StringJoiner(", ", "(", ")"); |
| 22 | |
| 23 | for(Parameter param : paramArr) { |
| 24 | String paramName = param.getName(); |
| 25 | Class paramType = param.getType(); |
| 26 | |
| 27 | paramList.add(paramType.getName() + " " + paramName); |
| 28 | } |
| 29 | |
| 30 | System.out.printf("%s %s%s%n", returnType.getName(), name, paramList); |
| 31 | } |
| 32 | } // main |
| 33 | } |
| 34 | |
| 35 | /* [실행결과] |