Hi,
I'm trying to dispatch objects to separate method according to their subclass.
For instance, consider those 2 objects
class A extends I {}
class B extends I {}
and the method
void dispatch(I i) {}
in dispatch(), I'd like to invoke a method according to the type of i. Hence if i is actually of type A, the handlerA(A a) method will be called. If it's of type B, handlerB(B b) will be called, and so on ... I tried with method overloading but I guess it doesn't work this way
what is the best way to achieve this ? I'd like to avoid using if/else statement ...
Thanks in advance,
edit: I can't modify any of those classes.