What do I return if the return type of a method is Void? (Not void!)
Posted
by DR
on Stack Overflow
See other posts from Stack Overflow
or by DR
Published on 2009-03-24T09:31:54Z
Indexed on
2010/04/03
12:33 UTC
Read the original article
Hit count: 479
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() {
//...
}
and the compiler demands that I return something. For now I'm just returning null
, but I'm wondering if that is good coding practice...
I've also tried Void.class
, void
, Void.TYPE
, new Void()
, no return at all, but all that doesn't work at all. (For more or less obvious reasons) (See this answer for details)
- So what am I supposed to return if the return type of a function is
Void
? - What's the general use of the
Void
class?
EDIT: Just to spare you the downvotes: I'm asking about V?oid, not v?oid. The class Void
, not the reserved keyword void
.
© Stack Overflow or respective owner