Instanceof accepts null values

Source: Internet
Author: User

During encoding, you are often reminded to avoid null values.

I have no intention of thinking about instanceof today. I tried to find that this operator accepts null values and returns false if a null object is encountered. Nullexceptinexception is not reported.

Perhaps the same, it is not a very obvious class method call. Or the JVM performs special processing on it.

Package com. jfans;

Public class instanceofdemo {

Public static void main (string [] ARGs ){

Object OBJ = NULL;

String S = "Hello, wrold! ";

String STR = NULL;

System. Out. println (s instanceof string );

System. Out. println (STR instanceof string );

System. Out. println (OBJ instanceof object );

}

}


Result:

True

False

False

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.