Home >Java >javaTutorial >What does void mean in java?
void in Java means that the method does not return any value and is used for method declaration (no return type is used), method invocation (no need to receive a return value), null pointer representation, wildcard type and lambda expression parameters.
The meaning of void in Java
void is a keyword in Java, mainly used in the following scenarios :
1. Method declaration
When a method does not return any value, you can use the void keyword in the method declaration instead of the return type. For example:
<code class="java">public void printMessage() { System.out.println("Hello, world!"); }</code>
2. Method call
When calling a method with a return type of void, there is no need to use a variable to receive its return value. For example:
<code class="java">printMessage(); // 输出 "Hello, world!"</code>
3. Other uses
void can also be used for:
Notes:
The above is the detailed content of What does void mean in java?. For more information, please follow other related articles on the PHP Chinese website!