BUG: Jvc.exe Gives Ambiguity Error on Overloaded Methods

Last reviewed: January 29, 1998
Article ID: Q177166
The information in this article applies to:
  • SDK for Java, version 2.0, 2.01
  • Microsoft Visual J++, versions 1.0, 1.1

SYMPTOMS

When 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)'

CAUSE

A 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.

RESOLUTION

To 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.

STATUS

Microsoft 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 INFORMATION

To 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);
   }


REFERENCES

For 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


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 29, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.