The instanceof keyword is used to determine whether an object that a reference type variable points to is an instance of a class (or interface, abstract class, parent class).

Source: Internet
Author: User
Tags java keywords

http://lavasoft.blog.51cto.com/62575/79864/Deep java keyword instanceof2008-06-02 07:50:43Tags: Java keywords casual workplace instanceof original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://lavasoft.blog.51cto.com/62575/79864 in-depth java keyword instanceof instanceof keyword is used to determine whether a reference type variable points to an object that is a class (or interface, abstract class, The parent Class) instance. As an example: PublicInterfaceIobject {
}

PublicclassFooImplementsiobject{
}

PublicclassTestextendsfoo{
}

Publicclassmultistatetest {
PublicStaticvoidMain (String args[]) {
Test ();
}

PublicStaticvoidTest () {
Iobject f=NewTest ();
if(finstanceofJava.lang.Object) System.out.println ("true");
if(finstanceofFoo) System.out.println ("true");
if(finstanceofTest) System.out.println ("true");
if(finstanceofIobject) System.out.println ("true");
}
} Output:true
true
true
trueIn addition, array types can be compared using instanceof. such as String str[] = new string[2], then str instanceof string[] will return true.

This article is from the lava blog, so be sure to keep this source http://lavasoft.blog.51cto.com/62575/79864

The instanceof keyword is used to determine whether an object that a reference type variable points to is an instance of a class (or interface, abstract class, parent class).

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.