How to determine an object's class?

后端 未结 11 1150
醉酒成梦
醉酒成梦 2020-11-22 17:10

If class B and class C extend class A and I have an object of type B or C, how can I determine of which type

11条回答
  •  情深已故
    2020-11-22 17:34

    There is also an .isInstance method on the "Class" class. if you get an object's class via myBanana.getClass() you can see if your object myApple is an instance of the same class as myBanana via

    myBanana.getClass().isInstance(myApple)
    

提交回复
热议问题