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