자바 반사 접근 private 방법

592 단어
mport java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ReflectDemo {
	public static void main(String[] args) throws Exception {
		Method method = PackageClazz.class.getDeclaredMethod("privilegedMethod", new Class[]{String.class,String.class});   
		method.setAccessible(true);
		method.invoke(new PackageClazz(), "452345234","q31234132");
	}
}

class PackageClazz {
	private void privilegedMethod(String invokerName,String adb) {
		System.out.println("---"+invokerName+"----"+adb);
	}
}

좋은 웹페이지 즐겨찾기