What is the correct way to return a Void
type, when it isn't a primitive? Eg. I currently use null as below.
interface B<E>{ E method(); }
class A implements B<Void>{
public Void method(){
// do something
return null;
}
}
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.
So any of the following would suffice:
Object
and returning new Object()
or null
Void
and returning null
NullObject
of yoursYou can't make this method void
, and anything else returns something. Since that something is ignored, you can return anything.