Java - 带反射的NoSuchMethodException

Lui*_*Sep 1 java reflection

NoSuchMethodException执行时我得到了:

operacionDTO.getClass().getMethod("setPrioridad").invoke(operacionDTO, 0);

java.lang.NoSuchMethodException: xxxx.api.service.dto.RegasificacionDTO.setPrioridad()
Run Code Online (Sandbox Code Playgroud)

但是类RegasificacionDTO确实有一个调用的公共方法setPrioridad(int i),如果在调试时调用我:

operacionDTO.getClass().getMethods()
Run Code Online (Sandbox Code Playgroud)

然后我得到一个方法数组,其中有一个setPrioridad.我尝试了一些其他类似的方法,我得到了同样的错误.

Thi*_*ilo 11

您需要包含参数签名.

 operacionDTO.getClass().getMethod("setPrioridad", Integer.TYPE)
Run Code Online (Sandbox Code Playgroud)