任何人都可以帮我找到JAVA中方法的返回类型.我试过这个.但不幸的是它不起作用.请指导我.
Method testMethod = master.getClass().getMethod("getCnt");
if(!"int".equals(testMethod.getReturnType()))
{
System.out.println("not int ::" + testMethod.getReturnType());
}
Run Code Online (Sandbox Code Playgroud)
输出:
不是int :: int
Gab*_*tti 13
该方法getReturnType()返回Class
你可以试试:
if (testMethod.getReturnType().equals(Integer.TYPE)){
.....;
}
Run Code Online (Sandbox Code Playgroud)
if(!int.class == testMethod.getReturnType())
{
System.out.println("not int ::"+testMethod.getReturnType());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26394 次 |
| 最近记录: |