What is the need of Void class in Java [duplicate]
It also contains Void.TYPE
, useful for testing return type with reflection:
public void foo() {}
...
if (getClass().getMethod("foo").getReturnType() == Void.TYPE) ...
Say you want to have a generic that returns void for something:
abstract class Foo<T>
{
abstract T bar();
}
class Bar
extends Foo<Void>
{
Void bar()
{
return (null);
}
}