Class<?> cls = Class.forName("패키지명" + "class 이름");//클래스의 메타정보 불러오기
Object obj = cls.newInstance();//메타정보로 인스턴스 생성해서 메모리에 올리기
//여기까지는 new class
Class<?> dtoCls = obj.getClass();//생성한 인스턴스로 클래스 형태로 불러오기

//Field 가져오기
Field field[]= dtoCls.getDeclaredFields(); //public으로 지정한 field명 가져오기

//Method 사용법
//생성자 있는 경우
Method setMethod = dtoCls.getMethod("set" + column, String.class); //method 불러오기
setMethod.invoke(obj, data); // method 실행

//return 있는 경우
Method getMethod = dtoCls.getMethod("get" + column); //method 불러오기
String result=getMethod.invoke(obj); // method 실행

 

 

 

 

 

[Java] 자바 - 리플렉션(Reflection)

* 리플렉션에 관한 소스코드가 있어 담아왔습니다 ~ - 리플렉션이란 컴파일시간에 클래스 정보를 분석하는 ...

blog.naver.com

 

https://javacan.tistory.com/tag/Method.invoke%28%29

 

'Method.invoke()' 태그의 글 목록

최범균이 운영하는 자바 및 웹 관련 컨텐츠 제공 블로그

javacan.tistory.com

 

https://pupustory.tistory.com/192

 

자바 리플랙션 필드값 수정(Java Reflection field value edit)

메소드 호출에 이어 이번엔 필드값을 수정해 보자. 이번에도 바로 코드부터 살펴보자. Exam_ReflectionField.java package pupustory.reflection.exam; import java.lang.reflect.*; public class Exam_Reflection..

pupustory.tistory.com

 

https://futurists.tistory.com/43

 

자바 동적로딩 이해(델리게이션 모델)

자바 프로그램은 한 개 혹은 그 이상의 클래스들의 조합으로 실핸된다. 그리고 실행 시 모든 클래스 파일드이 한 번에 JVM 메모리에 로딩되지 않고 요청되는 순간 로딩된다. 자바의 클래스 로더가 이런 역할을 수..

futurists.tistory.com

 

 

+ Recent posts