The method XXX is ambiguous for the type XX
Eclipse compilation error.
Analysis Reason: Method ambiguity, which is not determined by the compiler, which method is used in the code.
1, the call is the method of their own writing
public class Ambiguous {
public static void Main (string[] args) {
Ambiguous ambiguous = new ambiguous ();
Ambiguous. Para (NULL);
}
public void Para (String a) {
System.out.println ("String Type a" + a);
}
public void Para (StringBuffer a) {
System.out.println ("StringBuffer" + a.tostring ());
}
}
Obviously null as a parameter causes the compiler to not recognize which method to call.
In this case, one exception is that if the parameter of the method has an inheritance relationship, then the compiler can determine which method to call, and the principle is "I want you to have it."
2, call the library method.
Some library static methods are many static fields, which are often written to facilitate invocation calls:
Import static org.csdn.linghushaoxia.demo.*;
<pre name= "code" class= "java" >import static org.csdn.linghushaoxia.demo1.*;
If, incidentally, in other packages, there is the same method, can be troublesome, not easy to find.
For example, the Demo.init () static method is called, and the code writes init () directly;
There are Demo1.init () in the Demo1, and the code is written directly to Init (), which inevitably causes ambiguity.
After finding out the ambiguity, it is good to solve, plus the package on it.
This way:
Org.csdn.linghushaoxia.Demo.init ();
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java calling method causes ambiguity: The method XXX is ambiguous for the type XX