Java instanceof with class name

后端 未结 5 1814
抹茶落季
抹茶落季 2021-02-20 00:45

I am just curious to ask this, maybe it is quite meaningless.

When we are using instanceof in java, like:

if (a instanceof Parent){ //\"Parent\" here is          


        
5条回答
  •  不思量自难忘°
    2021-02-20 01:09

    Parent is the name of a type. Parent.class is essentially a static variable that refers to an object (specifically, an instance of Class). You want to ask whether a is an instance of the Parent type, not whether it's an instance of an object that is itself an instance of some other type (named Class).

提交回复
热议问题