title: Overloading in Java and multiple dispatch
body: <p>I have a collection (or list or array list) in which I want to put both String values and double values. I decided to make it a collection of objects and using overloading ond polymorphism, but I did something wrong.</p>
  
  <p>I run a little test:</p>
  
  <pre><code>public class OOP {
      void prova(Object o){
          System.out.println("object");
      }
  
      void prova(Integer i){
      System.out.println("integer");
      }
  
      void prova(String s){
          System.out.println("string");
      }
  
      void test(){
          Object o = new String("  ");
          this.prova(o); // Prints 'object'!!! Why?!?!?
      }
  
      public static void main(String[] args) {
          OOP oop = new OOP();
          oop.test(); // Prints 'object'!!! Why?!?!?
      }
  }
  </code></pre>
  
  <p>In the test seems like the argument type is decided at compile time and not at runtime. Why is that?</p>
  
  <p>This question is related to:</p>
  
  <p><a href="https://stackoverflow.com/questions/154577/polymorphism-vs-overriding-vs-overloading">Polymorphism vs Overriding vs Overloading</a> <br>
  <a href="https://stackoverflow.com/questions/210460/try-to-describe-polymorphism-as-easy-as-you-can">Try to describe polymorphism as easy as you can</a></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Ok the method to be called is decided at compile time. Is there a workaround to avoid using the <code>instanceof</code> operator?</p>