BUG: Jvc.exe Gives Ambiguity Error on Overloaded MethodsLast reviewed: January 29, 1998Article ID: Q177166 |
The information in this article applies to:
SYMPTOMSWhen using the new Java compiler provided in the Microsoft SDK for Java 2.0 (Jvc.exe version 1.02.4337), compiling code with overloaded methods whose parameters are various combinations of double and long types gives the following error:
Ambig.java(14,5) : error J0079: Ambiguity between 'void Ambig.foo(double d, long l)' and 'void Ambig.foo(long l, double d)' CAUSEA bug in the Java Compiler (Jvc.exe) produces this error when the overloaded method that takes two doubles appears in the code first and directly before the method that takes two longs.
RESOLUTIONTo work around this problem, either move the method that takes two doubles to any point in the class after the method that takes two longs, or move the method that takes two longs anywhere in the code after the other overloaded methods.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONTo reproduce the problem, compile the following code:
public class Ambig { public static void main(String args[]) { Ambig b = new Ambig(); b.foo((long)1, (double)2); b.foo((double)1, (long)2); b.foo(1,2); b.foo(1.5,2.5); // pause for user to press return try{System.in.read();}catch(Exception e){} } public void foo(double d, double d2) { System.out.println("Double = "+d+" Double2 = "+d2); } public void foo(long l, long l2) { System.out.println("Long = "+l+" Long2 = "+l2); } public void foo(long l, double d) { System.out.println("Long = "+l+" Double = "+d); } public void foo(double d, long l) { System.out.println("Double = "+d+" Long = "+l); } }You should see the following error:
Ambig.java(14,5) : error J0079: Ambiguity between 'void Ambig.foo(double d, long l)' and 'void Ambig.foo(long l, double d)'To work around this problem, change the order of the overloaded methods to the following:
public void foo(long l, long l2) { System.out.println("Long = "+l+" Long2 = "+l2); } public void foo(long l, double d) { System.out.println("Long = "+l+" Double = "+d); } public void foo(double d, long l) { System.out.println("Double = "+d+" Long = "+l); } public void foo(double d, double d2) { System.out.println("Double = "+d+" Double2 = "+d2); } -or- public void foo(double d, double d2) { System.out.println("Double = "+d+" Double2 = "+d2); } public void foo(long l, double d) { System.out.println("Long = "+l+" Double = "+d); } public void foo(double d, long l) { System.out.println("Double = "+d+" Long = "+l); } public void foo(long l, long l2) { System.out.println("Long = "+l+" Long2 = "+l2); } REFERENCESFor the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:
http://support.microsoft.com/support/visualj/ http://support.microsoft.com/support/java/ Keywords : kberrmsg VJMisc Technology : kbInetDev Version : WINDOWS:1.0,1.1,2.0,2.01 Platform : WINDOWS Issue type : kbbug |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |