I'm currently reviewing for OCA exam and thought int/float method would work on the third test.
In OCA Study Guide of Jeane Boyarsky only says 4 order rules to choose the right overloaded method.
- Exact match by type
- Larger primitive type
- Autoboxed type
- Varargs
Can someone explain why java says it's ambiguous?
public static void main(String... args){
OverLoadingMethod ov=new OverLoadingMethod();
ov.test(1F,2);
ov.test(1,2F);
ov.test(1,2);
}
public void test(float i,int j){
System.out.println("float/int");
}
public void test(int i,float j){
System.out.println("int/float");
}
public void test(float i,float j){
System.out.println("float/float");
}
Produces this error
OverLoadingMethod.java:12: error: reference to test is ambiguous
ov.test(1,2);
^
both method test(float,int) in OverLoadingMethod and method test(int,float) in OverLoadingMethod match