标签:declare ble stack pre vat 设置 obj color 访问
1 public class Calcu { 2 3 private int add(int a,int b) { 4 return a+b; 5 } 6 }
public class CalcuTest{ public static void main(String[] args) { Calcu ca=new Calcu(); Class<Calcu> clazz=Calcu.class; Object res=null; try { //返回一个方法对象, Method m=clazz.getDeclaredMethod("add", new Class[] {Integer.TYPE,Integer.TYPE}); m.setAccessible(false);//设置为true才能访问private res=m.invoke(ca, new Object[] {2,3}); }catch(Exception e) { e.printStackTrace(); } finally { System.out.println(res); } } }
标签:declare ble stack pre vat 设置 obj color 访问
原文地址:https://www.cnblogs.com/liamlee/p/9340799.html