What is the difference between return and return null in Java?

Source: Internet
Author: User
What is the difference between return and return null in Java?

The biggest difference:
Return
The return value of the method must be void!
return null;
The return value of the method must not be the original data type (the wrapper class has been removed) and the void!

Return is the way to jump out ...
Return null also jumps out of the method and returns null:

That is, return null must be used in a method that returns a value other than void:
Return can be used in any method

Do not assume that NULL is not a value. Null is the value.
The real no value is ...
such as you string s, this time S is no value. But if string s = Null;s are all valued: Just a value of NULL

What is the difference between return and return null in Java?

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.