V
VisionSet
Usually we prefer to avoid instanceof and just call objects by their
interface type for example and use the fact that the various classes will
have implemented the method appropriately.
I have 10 subclasses directly extending Super and all implement a method
doSomething()
eg
class SubA extends Super {
void doSomething(Super arg) {
if(arg instanceof SubA) //do something
if(arg instanceof SubB) //do something
if(arg instanceof SubC) //do something
}
}
Each subclass has something similar, but the something that they do can not
be done in a generic way because it depends on which subclass instigates it.
I don't think I can do this in any other way than instanceof or
Class.isInstance()
Or... am I having a stupid day again?
interface type for example and use the fact that the various classes will
have implemented the method appropriately.
I have 10 subclasses directly extending Super and all implement a method
doSomething()
eg
class SubA extends Super {
void doSomething(Super arg) {
if(arg instanceof SubA) //do something
if(arg instanceof SubB) //do something
if(arg instanceof SubC) //do something
}
}
Each subclass has something similar, but the something that they do can not
be done in a generic way because it depends on which subclass instigates it.
I don't think I can do this in any other way than instanceof or
Class.isInstance()
Or... am I having a stupid day again?