If one needs return a Void type, which Javadoc describes as
A class that is an uninstantiable placeholder class to hold a
reference to the Class object representing the Java keyword void.
Why does the following still require null to be returned?
public Void blah() {
return null; // It seems to always want null
}
Voidis a class like any other, so a function returningVoidhas to return a reference (such asnull). In fact,Voidisfinaland uninstantiable, which means thatnullis the only thing that a function returningVoidcould return.Of course
public void blah() {...}(with a lowercasev) doesn’t have to return anything.If you’re wondering about possible uses for
Void, see Uses for the Java Void Reference Type?