Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is by design and a known area of incompatibility between Java 6 and Java 7 because the overload-resolution algorithm was fixed in Java 7. In Java 5 and 6, the following code would not compile:</p> <pre><code>class Test { void foo(int... i) {} void foo(double... d) {} void test() { foo(1,2,3); } } </code></pre> <p>The compiler would complain that the calls were ambiguous. But this isn't true because <code>double</code> is more general than <code>int</code> and therefore <code>int</code> is the most-specific option in this case.</p> <p>However this fix resulted in an incompatibility (look at the <a href="http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#jdk7" rel="nofollow">release notes</a>; search for "varargs"). The upshot is that you cannot choose the most-specific method when you have <code>int</code> and <code>Object</code> because neither is a subtype of the other. So this shouldn't compile. However, you can use <code>Integer</code>, because <code>Integer</code> is a subtype of <code>Object</code> and in this case it is the most-specific option and so the compiler can choose that.</p> <p>Pertinent section from the release notes:</p> <blockquote> <p>While the <code>javac</code> compiler accepts more code than it did prior to JDK 7, this fix also results in a slight source incompatibility in the following case:</p> </blockquote> <pre><code>class Test { void foo(int... i) {} void foo(Object... o) {} void test() { foo(1,2,3); } } </code></pre> <blockquote> <p>This code compiles in JDK 6 (the most specific method is <code>foo(int...)</code>). This code does not compile under JDK 7. As per <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.2.5" rel="nofollow">15.12.2.5</a>, it is not possible to choose between <code>foo(int...)</code> and <code>foo(Object...)</code> as neither <code>int</code> is a subtype of <code>Object</code>, nor <code>Object</code> is a subtype of <code>int</code>. This program should be disallowed (in fact, it should never have been allowed in the first place).</p> <p>Nature of Incompatibility: behavioral and source</p> <p>RFE: <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6199075" rel="nofollow">6199075</a></p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload