title: Determining which method will be executed (Type system)
body: <p>I have a question concerning Java's Type system.</p>
  
  <p>I have four classes A, B, AStar and BStar. 
  AStar extends A and Bstar extends B.</p>
  
  <p>On top of that I have another class that has the following
  methods:</p>
  
  <pre><code>public static void main(String[] args) {
      AStar a = new AStar();
      BStar b = new BStar();
  
      someMethod(a,b);
  }   
  
  public static void someMethod(A a,BStar b) {
      System.out.println("first");        
  }
  
  public static void someMethod(AStar a,B b) {
      System.out.println("second");
  }
  </code></pre>
  
  <p><strong>The implementation that is executed is the first one.</strong></p>
  
  <p>From my understanding, Java considers the static types 
  of the arguments and chooses the signature that is most
  specialized ("fits best") as the signature of the method 
  that will be called.</p>
  
  <p>While this rule of thumb works most of the time, it fails
  in a few cases with the example above being the 'base case' 
  (not involving polymorphism etc.)</p>
  
  <p>I spent a considerable amount of time looking for an explanation
  of this behaviour (online as well as in the java books I have
  at disposal here), but did not find anything.</p>
  
  <p><strong>I would be very grateful for an explanation or a link to a resource
  that explains this behaviour...</strong></p>
  
  <p>Thanks in advance</p>
  
  <p>Michael</p>