[Java] Reflection을 활용한 메서드, 필드 값 불러오기.
동적으로 다른 클래스의 메서드와 필드값을 불러와서 사용해야 하는 경우, Java Reflection을 활용하면 가능하다. // 메서드------------------------------------------------------------------------- Method getSomethingMethod = ClassName.getClass().getDeclaredMethod("getSomething", String.class); getSomethingMethod.setAccessible(true); // private 함수 접근 허용. String someString = (String) getSomethingMethod.invoke("something"); // 불러올 메서드가 static일 때...
공장 (factory)/- Programming..
2021. 1. 22. 19:55