I can't answer completely "why should we call "void" is 'return type'?"
How do I prove that "void" is a type?
void
is not a type, it is not also a return type:
in JLS 14.8 you can find a note about this type:
Note that the Java programming language does not allow a "cast to void"-void is not a type
The Java Language Specification says that:
[...] every variable and every expression has a type that can be determined at compile time. The type may be a primitive type or a reference type.
void
is not a valid type. However, void
is a valid keyword used to indicate that a method does not return a value.
The Void JavaDoc also says that void
is a keyword:
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void
Contrast that to the Integer JavaDoc:
The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.
The Void
class represents the void
keyword; while the Integer
class represents an int
type.
Quote:
TYPE
public static final Class TYPE
The Class object representing the primitive Java type void.
Taken from : http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Void.html
Or have I misunderstood the question?
Hope class void explains why void is a type.
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the Java keyword void.
public final class Void extends Object
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