반사 획득 사유 구조 방법 및 운행

790 단어 리플렉스
package cn.learn.demo1;

import java.lang.reflect.Constructor;

/*
 *               
 *     ,         ,   
 *      
 */
public class ReflectDemo4 {
	public static void main(String[] args) throws Exception{
		Class c = Class.forName("cn.learn.demo1.Person");
		//Constructor[] getDeclaredConstructors()         ,     
		/*Constructor[] cons = c.getDeclaredConstructors();
		for(Constructor con : cons){
			System.out.println(con);
		}*/
		//Constructor getDeclaredConstructor(Class...c)              
		Constructor con = c.getDeclaredConstructor(int.class,String.class);
		
		//Constructor ,  AccessibleObject,    setAccessible(boolean b)
		con.setAccessible(true);
		
		Object obj = con.newInstance(18,"lisi");
		System.out.println(obj);
	}
}

좋은 웹페이지 즐겨찾기