我试图通过Java反射调用一个方法,它没有任何参数:
Method getSelectedCriteriaMethod = multipleSorting.getClass().getDeclaredMethod("getSelectedCriteria", null);
EstimateSortField selectedCriteria = (EstimateSortField)getSelectedCriteriaMethod.invoke(multipleSorting, null);
这是工作,但我得到编译器警告:
warning: non-varargs call of varargs method with inexact argument type for last parameter;
cast to java.lang.Class<?> for a varargs call
non-varargs call of varargs method with inexact argument type for last parameter;
cast to java.lang.Object for a varargs call
调用没有任何参数的方法的正确方法是什么?
你可以直接写
selectedCriteria.invoke(multipleSorting);
getDeclaredMethod("getSelectedCriteria");
invoke(multipleSorting);