title: Best way to route method calling from List in Java
body: <p>What's definitely the best way to call a different method of a class according to a different object type in a List? </p>
  
  <p><em>common example:</em></p>
  
  <pre><code>public class Dog extends Animals{
    ...
    public void say(){
      System.out("i'm a dog");
  }
  
  public class Cat extends Animals{
    ...
    public void say(){
      System.out("i'm a cat");
  }
  
  public class OtherClass {
    public void route(){
      List&lt;Animals&gt; aList = new ArrayList&lt;&gt;();
      a.add(new Dog());
      a.add(new Cat());
      for(Animals a:aList)
       methodOverloaded(a); ---&gt; that's the point &lt;---
    }
    public methodOverloaded(Dog d){
      d.say();
    }
  
    public methodOverloaded(Cat c){
      c.say();
   }
  }
  </code></pre>
  
  <p>Of course, the metaphorical goal is print <code>I'm a dog</code> on the first iteration and <code>I'm a cat</code> on second running <code>methodOverloaded()</code>.</p>
  
  <p>I tried</p>
  
  <ul>
  <li>Visitor Pattern</li>
  <li><code>instanceOf()</code></li>
  </ul>
  
  <p>but I'm looking for better solution.</p>
  
  <p>edit : I stricrtly want to call the overloaded methods of example's <code>OtherClass</code>.</p>