What is void in Java? What's the effect?

Source: Internet
Author: User

Anyone who learns Java knows that void means null and is a keyword in java. Initially, when I knew void, it was public static void main (String[]args) {}, I remember when I was in contact with void, I always had no idea what it was, so I asked the teacher, but

The teacher just said void is not a what, you just remember void is empty, when the method declaration indicates that the method does not return the value of the line.

(no return value.) But you can use return in the method, to exit the method)

One day when learning the C data type, found that there are four types of data in C, there is actually empty type, it has such a saying "there is a class of functions, after the call does not need to return the function value to the caller, this function can be defined as" null type. Its type specifier is void, and my first reaction was, "since void in C is an empty type, what is void in Java?" ”

We all know that there are only two data types in Java, that is, the basic data type and the reference data type, what is void in Java, according to the syntax of the method declaration can be seen that the definition of the method must have a return value, you need to write out the type of the method return value, when the method definition with void decoration, Indicates that there is no return value, then the void should be considered a data type, it seems that Java does not define a data type of void, with such a problem, the search for information, there is such an explanation:

Classes in the Void-java.lang

The Void class is a non-instantiated placeholder class that maintains a reference to a class object that represents the Java keyword void.

VOID-Static variables in class Javax.management.openmbean.SimpleType

The SimpleType instance describes a value whose Java class name is java.lang.Void.

I hope that we will understand the void of some help.

What is void in Java? What's the effect?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.