当前位置: 代码迷 >> J2SE >> 关于反射,该怎么解决
  详细解决方案

关于反射,该怎么解决

热度:31   发布时间:2016-04-24 12:59:57.0
关于反射
使用 “反射” 能否访问到某个类的私有属性,能访问到私有方法么?

------解决方案--------------------
探讨
Java code
public static void main(String[] args){
Test test = new Test();
try {
Method method = Test.class.getMethod("test");
method.setAccessible(true);
method.invoke(test);

} catch (Exception e) {
e.printStackTrace();
}
}

private void test(){
System.out.println("ababc");
}




上面的报异常的!
能否详细指…
  相关解决方案