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

Java-instanceof summary code example

黄舟
黄舟Original
2017-03-15 11:38:571571browse

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 {


}
B  A{

}
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()}
    }

}
Run result:

true
true
false


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!

Statement:
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