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());
}
Output :
not int ::int
The method
getReturnType()returnsClassYou can try: