利用反射获取所有方法
-
getMethod(String name , Class <?> … parameterTypes)获得公共方法
Class fruitListClass=fruitList.getClass(); Method getApple = fruitListClass.getMethod("getApple"); Method setApple = fruitListClass.getMethod("setApple", Integer.class);
-
getMethods() 获取所有公共的方法,返回一个数组
Method[] methods = fruitListClass.getMethods();
-
getDeclaredmethod(String name,Class <?> … parameterTypes )可以获取所有权限的方法
Method getApple1 = fruitListClass.getDeclaredMethod("getApple"); Method setApple1 = fruitListClass.getDeclaredMethod("setApple", Integer.class);
-
getDeclaredmethods()
Method[] declaredMethods = fruitListClass.getDeclaredMethods();