The java documentation for Class.getName()
says:
Returns the name of the entity (
class
,interface
,array class
,primitive type
, orvoid
) represented by thisClass
object, as aString
.
When will it return void
?
The getName() method of java Class class is used to get the name of the entity, and that entity can be class, interface, array, enum, method, etc. of the class object.
getName() returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String.
It will give you void
String for class literal for void
type:
Class<Void> clazz = void.class;
System.out.println(clazz.getName());
Refer JLS § 15.8.2 for further reading:
A class literal is an expression consisting of the name of a class, interface, array, or primitive type, or the pseudo-type void, followed by a '.' and the token class.
[...]
The type of void.class (§8.4.5) isClass<Void>
.
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