Home > Java > javaTutorial > Java-instanceof summary code example

Java-instanceof summary code example

黄舟
Release: 2017-03-15 11:38:57
Original
1570 people have browsed it

What you learn on paper is shallow, but you know you have to do it in detail --Lu You Ask the canal how clear it is to have a source of living water --Zhu Xi


instanceof is actually a binary operator in Java, used to determine the object## on the left #Whether it is an instance of the specific class on the right or its subclass, return boolean type data. Generally, when using non-generic collections (List, set, etc.), instanceof is often used. Since collections can store various objects, they generally need to be read when reading. corresponding judgment.


instanceof instance:


A {


}
Copy after login
B  A{

}
Copy after login
Hello {

(String[] args) {
A a=A()B b=B()A aa=(a A)
        {
            System..println()}{
            System..println()}
(b A){
            System..println()}	else{
            System..println()}
(aa A)
        {
            System..println()}{
            System..println()}
    }

}
Copy after login
Run result:

true
true
false
Copy after login


The above is the detailed content of Java-instanceof summary code example. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template