Take the following code:
public interface InterfaceA { }
public interface InterfaceB { }
public class Abba implements InterfaceA, InterfaceB { }
public class MainThingy {
public static void main(String[] args) {
Abba abObj = new Abba();
int result = MainThingy.doStuff(abObj);
}
private static int doStuff(InterfaceA param) {
System.out.println("method A");
}
private static int doStuff(InterfaceB param) {
System.out.println("method B");
}
}
Since both doStuff() methods would take the Abba argument, it isn’t clear which one will be called. How does the Java compiler and/or JVM handle this?
Simple. This code doesn’t compile due to the ambiguous reference.