title: Differentiate blocks of code based on class without instanceof
body: <p>So I have the following inteface <code>I</code> which is implemented by classes <code>A</code> and <code>B</code>:</p>
  
  <pre><code>interface I { ... }
  class A implements I { ... }
  class B implements I { ... }
  </code></pre>
  
  <p>Then I have another interface <code>OverrideMe</code> whose method has an object <code>I</code> as parameter, and a class that overrides that method and behaves differently depending on the actual class of that parameter:</p>
  
  <pre><code>interface OverrideMe {
     void method(I parameter)
  }
  
  class Overriding implements OverrideMe {
     @Override
     void method(I parameter) {
        if (I instanceof A) {
           // Code block for A
        }
        else if (I instanceof B) {
           // Code block for B
        }
     }
  }
  </code></pre>
  
  <p>Is there a way differentiate both blocks of code by type and without using <code>instanceof</code>? I am not sure if this could be done using inheritance.</p>
  
  <p>Keep in mind that I have no control on <code>I</code>, <code>A</code>, <code>B</code> and , I have to use them as they are.</p>