标签:
public class Calculator2{ private int add(int a,int b){ return a+b; } }
public class Test { public static void main(String[] args){ Calculator2 calculator2 = new Calculator2(); Class<Calculator2> clazz = Calculator2.class; Object result = null; try{ Method method = clazz.getDeclaredMethod("add", new Class[]{Integer.TYPE,Integer.TYPE}); method.setAccessible(true); result = method.invoke(calculator2, new Object[]{2,3}); }catch (Exception e) { e.printStackTrace(); }finally{ System.out.println(result); } } }
标签:
原文地址:http://www.cnblogs.com/weitangmonkey/p/5157623.html