title: Java 8 chooses different overloaded method than Java 7 did when generics are involved
body: <p>I have the following test class:</p>
  
  <pre><code>import java.io.Serializable;
  public class Java8Problem {
  
      public void test(String stringArg) {
          System.out.println("string-Method taken: " + stringArg);
      }
  
      public void test(Object objectArg) {
          System.out.println("object-Method taken: " + objectArg.toString());
      }
  
      public &lt;T extends Serializable&gt; T getTestData() {
          return (T) new Integer(10);
      }
  
      public static void main(String[] arguments) {
          Java8Problem instance = new Java8Problem();
          instance.test(instance.getTestData());
      }
  
  }
  </code></pre>
  
  <p>When i compile and run this class in Java 7 the output will be: </p>
  
  <blockquote>
    <p>object-Method taken: 10</p>
  </blockquote>
  
  <p>But when i compile and run this class in Java 8 i get a runtime exception:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ClassCastException:
    java.lang.Integer cannot be cast to java.lang.String
            at Java8Problem.main(Java8Problem.java:21)</p>
  </blockquote>
  
  <p>So Java 8 seems to takes the most specific method whereas Java 7 takes the most common one.</p>
  
  <p>Does anybody knows if this is a bug in Java 8 or is it changed/desired behaviour? If the latter is the case is there any possibility to configure Java 8 to use the old behaviour? Or is there any other way to solve this?</p>
  
  <p>BTW: i know that the problem here is caused by the return type of method getTestData but this is only a simplified example of my real world problem in which i cannot easily change the signature of that method.</p>