I have a method that receives an Object and does something based on what type of object it detects:
void receive(Object object) {
if (object instanceof O
Never had a goal to "reduce the cyclomatic complexity", though there were times when I was paid by LOC.
You code is "good enough". My eyes stumble on brackets, so I'd sacrifice a bit of performance and did the following (providing types A, B and so on are not in the same hierarchy):
receive(Object object) {
if (object intanceof ObjectTypeA) doSomethingA();
if (object instanceof ObjectTypeB) doSomethingB();
...
or (if they are in the same hierarchy):
receive(Object object) {
if (object intanceof ObjectTypeA) { doSomethingA(); return; }
if (object instanceof ObjectTypeB) { doSomethingB(); return; }
...
Don't know if it would reduce the cyclomatic thingy, and couldn't care less.