How to find if a method returns void?
Normally this is the question which comes when using reflection to find the return type of a method. Void class comes to rescue.
public class VoidClassApp { public static void main(String[] args) throws NoSuchMethodException { Class clazz = Test.class.getMethod("method").getReturnType(); System.out.println(clazz == Void.TYPE); } } class Test { public void method() { System.out.println("Does Nothing"); } }
The output is : true
Posted on April 27, 2011, in java and tagged java. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0