Java-instanceof Summary

Source: Internet
Author: User

The paper came to the end of shallow, I know this matter to preach-Luask the canal that is clear so, for have fountainhead come--Zhu Xi

Instanceof is actually a Java two-dollar operator that is used to determine whether the left-hand object is a specific class on the right or an instance of its subclass, returning a Boolean type of data. Generally in the use of non-generic collections (List, set, etc.), more use of instanceof, because the collection can save a variety of objects, so in the read generally to make appropriate judgments.
instanceof instances:
A


}
B  a{

}
Public classHello {

Public static voidMain(string[] args) {
// TODO Auto-generated method stubs
A a=NewA ();
B b=NewB ();
A aa=null;
if(AinstanceofA
{
System. out. println ("true");
}
Else
  { 
System. out . println (" false "" ;
}
if (b instanceof A)  
{
System. out. println ("true");
}
Else
{
System. out. println ("false");
}
//aais not instantiated, so it isfalse
If(AAinstanceofA
{
System. out. println ("true");
}
Else
{
System. out. println ("false");
}
}

}
Running Result: Truetruefalse

Copyright Notice: Knowledge is to share, technology lies in communication, please leave a blogger's link on the reprint.

Java-instanceof Summary

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.