, , .
, B A, , (), IsAssignableFrom (...).
For example, if your object exists, if type B and you want it to call dispatch(B obj)and dispatch(C obj), you need to make these calls accordingly:
if (A.isAssignableFrom(obj.getClass())) { dispatchA(obj); }
if (B.isAssignableFrom(obj.getClass())) { dispatchB(obj); }
if (C.isAssignableFrom(obj.getClass())) { dispatchC(obj); }
Never use instanceof, because in this case it will not work.
source
share