Due to the use of Generics in Java I ended up in having to implement a function having Void
as return type:
public Void doSomething() {
//..
To make clear why the other suggestions you gave don't work:
Void.class
and Void.TYPE
point to the same object and are of type Class
, not of Void
.
That is why you can't return those values. new Void()
would be of type Void
but that constructor doesn't exist. In fact, Void
has no public constructors and so cannot be instantiated: You can never have any object of type Void
except for the polymorphic null
.
Hope this helps! :-)