Java - 带反射的NoSuchMethodException [英] Java - NoSuchMethodException with reflection

查看:214
本文介绍了Java - 带反射的NoSuchMethodException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行时我得到 NoSuchMethodException

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

java.lang.NoSuchMethodException: xxxx.api.service.dto.RegasificacionDTO.setPrioridad()

但是类 RegasificacionDTO 确实有一个名为 setPrioridad(int i)的公共方法,如果有的话调试我打电话:

But class RegasificacionDTO does have a public method called setPrioridad(int i), and if when debugging I call:

operacionDTO.getClass().getMethods()

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

Then I get an array of Method in which there is a setPrioridad. I've tried with some other similar methods and I get the same error.

推荐答案

您需要包含参数签名。

 operacionDTO.getClass().getMethod("setPrioridad", Integer.TYPE)

这篇关于Java - 带反射的NoSuchMethodException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆