Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't autoboxing overrule varargs when using method overloading in Java 7?
    primarykey
    data
    text
    <p>We have a class LogManager in our Java project which looks like this:</p> <pre><code>public class LogManager { public void log(Level logLevel, Object... args) { // do something } public void log(Level logLevel, int value, Object... args) { // do something else } } </code></pre> <p>When compiling the project with <em>OpenJDK 6</em> under Debian everyting works fine. When using <em>OpenJDK 7</em> the build (done with ant) produces the following errors and the build fails:</p> <pre><code>[javac] /…/LogManager.java:123: error: reference to log is ambiguous, both method log(Level,Object...) in LogManager and method log(Level,int,Object...) in LogManager match [javac] log(logLevel, 1, logMessage); [javac] ^ [javac] /…/SomeOtherClass.java:123: error: reference to log is ambiguous, both method log(Level,Object...) in LogManager and method log(Level,int,Object...) in LogManager match [javac] logger.log(logLevel, 1, logMessage); [javac] ^ </code></pre> <p>As long as the <em>1</em> is not autoboxed, the method call should be unambiguous as <em>1</em> is an int and cannot be upcast to Object. So why doesn't autoboxing overrule varargs here?</p> <p>Eclipse (installed using the tar.gz from eclipse.org) compiles it no matter if OpenJDK 6 is installed or not.</p> <p>Thank's a lot for your help!</p> <p><strong>Edit:</strong></p> <p>The compiler gets the option <code>source="1.6"</code> and <code>target="1.6"</code> in both cases. The Eclipse compiling note is just meant as a comment.</p>
    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.
 

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