youki吧 关注:112贴子:14,641
  • 1回复贴,共1
getClass() will be useful when you want to make sure your instance is NOT a subclass of the class you are comparing with.
Java代码
class A { }
class B extends A { }
Object o1 = new A();
Object o2 = new B();
o1 instanceof A => true
o1 instanceof B => false
o2 instanceof A => true // <================ HERE
o2 instanceof B => true
o1.getClass().equals(A.class) => true
o1.getClass().equals(B.class) => false
o2.getClass().equals(A.class) => false // <===============HERE
o2.getClass().equals(B.class) => true


1楼2014-04-03 10:34回复
    3楼2015-06-07 15:09
    回复