I am not clear with the class java.lang.Void
in Java. Can anybody elaborate in this with an example.
void. class is the object used in reflection to indicate that a method has void return type.
Creating a copy using the clone() method The class whose object's copy is to be made must have a public clone method in it or in one of its parent class. Every class that implements clone() should call super. clone() to obtain the cloned object reference. The class must also implement java.
The void keyword in Java denotes that a method does not have a return type. However, even though a constructor method can never have a return type, it does not have the void keyword in its declaration.
- Unlike the other wrappers Void class doesn't store a value of type void in itself and hence is not a wrapper in true essence. - The Void class according to javadoc exists because of the fact that some time we may need to represent the void keyword as an object.
It also contains Void.TYPE
, useful for testing return type with reflection:
public void foo() {} ... if (getClass().getMethod("foo").getReturnType() == Void.TYPE) ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With