Say I have 3 classes like so:
class A {}
class B extends A {}
class C extends A {}
Would it then be possible to determine whether a particular object was an instance of A
, B
, or C
?
I thought that something like this might work:
if (myObject.getClass().isInstance(B.class)) {
// do something for B
} else (myObject.getClass().isInstance(C.class)) {
// do something for C
} else {
// do something for A
}
but after reading a little I think it would always evaluate as B since it's just testing if a cast would work and there's no substantial differences between them.