我在MatrixOperation类中定义了此方法:
private static int getLargestSubMatrixSize(int[][] inputMatrix, int[][] arrResult){}
我需要使用反射调用此方法
我尝试了这种方法,但是得到了NoSuchMethodException
:
Method method = MatrixOperations.class.getMethod("getLargestSubMatrixSize", int[][].class, int[][].class);
method.setAccessible(true);
int maxCount = (int) method.invoke(null, inputMatrix, resultMatrix);
如何做到这一点?
您的方法是private
并且getMethod
仅返回公共方法:
返回一个Method对象,该对象反映此Class对象表示的类或接口的指定公共成员方法。
您要使用的是getDeclaredMethod
:
返回一个Method对象,该对象反映此Class对象表示的类或接口的指定声明的方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句