FIX: Jvc.exe Gives Ambiguity Error on Overloaded Methods (177166)



The information in this article applies to:

  • Microsoft SDK for Java 2.0
  • Microsoft SDK for Java 2.01
  • Microsoft SDK for Java 2.02
  • Microsoft Visual J++ 1.0
  • Microsoft Visual J++ 1.1

This article was previously published under Q177166

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 that this is a bug in the Microsoft products that are listed at the beginning of this article.
This bug was corrected in Microsoft virtual machine contained in the SDK for Java 3.0 and later.

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:

Modification Type:MinorLast Reviewed:8/25/2005
Keywords:kbbug kberrmsg kbfix kbSDKJava300fix kbSDKJava310fix KB177166