The relationship between the Java object Type Boolean and the base type Boolean

Source: Internet
Author: User

These two days in the writing class of the judgment method, such as Ispeople (): Boolean, if the error returns null. An error occurs when the return type is Boolean.

After debugging, the return type is Boolean without error. A little puzzled. After finding the data, I found that I did not understand the object types and basic types of java.

Object type:

Example: Java.lang.Boolean wraps a base type Boolean in an object and contains only one field of type Boolean. In addition, this type provides a number of methods for Boolean and string conversions, and provides other constants and methods that are useful when dealing with Boolean.

Basic type: Or a built-in type, is a special type in Java that is different from a class. They are the most frequently used types in our programming.

Therefore, when the return type is a base type, the return value cannot have null because it is not an object. If the return type is Boolean, the return value must be true or false. However, when the return type is an object type, NULL can be returned because the object is nullable.

Note:

Basic types can be grouped into three categories, character type char, Boolean-type Boolean, and numeric type Byte, short, int, long, float, double. Numeric types can also be divided into integer type Byte, short, int, long, and floating-point type float, double. Numeric types in Java do not have unsigned, and their range of values is fixed and will not change as the machine hardware environment or operating system changes. In fact, there is another basic type Void in Java, which also has the corresponding wrapper class java.lang.Void, but we can't manipulate them directly.

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.