Overview
Void is a keyword in Java, often encountered in daily development, the Java Main method is defined in the form of void, as follows:
public static void Main (string[] args) {
}
People who have studied Java know that void means empty, and if you ask an old hand, an old hand will tell you, "Void is nothing, you just remember void is empty, and when the method is stated, the method has no return value". what void is.
The Java language is strongly typed (strong typed), from the syntax of the method declaration, you can see that the definition of the method must have a return value, the type of the method return value needs to be determined, and when the method definition is void decorated with no return value, then void should be considered a data type. In Java, there are only two types of data, the basic data type and the reference data type, and the basic data types (8 types) are as follows:
Data Type |
type |
Packing class |
Basic type |
Byte |
Java.lang.Byte |
Basic type |
Short |
Java.lang.Short |
Basic type |
Int |
Java.lang.Integer |
Basic type |
Long |
Java.lang.Long |
Basic type |
Float |
Java.lang.Float |
Basic type |
Double |
Java.lang.Double |
Basic type |
Char |
Java.lang.Character |
Basic type |
Boolean |
Java.lang.Boolean |
Reference type:
Include class, collection collection class, custom class, and so on.
So what are the types of void in Java?
In fact, Void also has a corresponding wrapper class java.lang.Void, but we cannot directly operate on them. It inherits from object, as follows:
Public final class Void extends Object {
/
* * The Void class cannot be instantiated.
* *
Private Void () {}
}
The void class, like the string class, is defined as final, so it cannot be extended; In addition, its construction method is privatized so it cannot be instantiated.
A void class is a placeholder class that is not instantiated to hold a reference to a class object that represents the Java keyword void.