instanceof 在java中是一个二元操作符,相当于== 、<、>等,
A instanceof B 表示对象A是否是类B的一个实例,
例如:
interface Domestic {}
class Animal {}
class Dog extends Animal implements Domestic {}
class Cat extends Animal implements Domestic {}
设Object dog = new Dog()
, 则:
dog instanceof Domestic // true - Dog implements Domestic
dog instanceof Animal // true - Dog extends Animal
dog instanceof Dog // true - Dog is Dog
dog instanceof Object // true - Object is the parent type of all objects
dog instanceof Cat // false
更多实例见
http://stackoverflow.com/questions/7313559/what-is-the-instanceof-operator-used-for