如何在JAVA中找到方法的返回类型? [英] How to find return type of a Method in JAVA?

查看:58
本文介绍了如何在JAVA中找到方法的返回类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮助我在JAVA中找到方法的返回类型.我试过了但不幸的是,它不起作用.请指导我.

Could anyone help me find the return type of a method in JAVA. I tried this. But unfortunately it doesn't work. Please guide me.

 Method testMethod = master.getClass().getMethod("getCnt");

  if(!"int".equals(testMethod.getReturnType()))
   {
      System.out.println("not int ::" + testMethod.getReturnType());
   }

输出:

不是int :: int

not int ::int

推荐答案

方法 getReturnType()返回 Class

您可以尝试:

if (testMethod.getReturnType().equals(Integer.TYPE)){ 
      .....;  
}

这篇关于如何在JAVA中找到方法的返回类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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