If there are two methods, for example add(int,long) and add(long,int) , such a call to add(10,10) will be considered an ambiguity.
But what if we have such an example, why is it still considered ambiguity?
static void add(short num1, short num2) { System.out.println("add(short, short)"); } static void add(byte num1, long num2) { System.out.println("add(byte, long)"); } public static void main(String[] args) { byte num1 = 10; byte num2 = 10; add(num1, num2); }
I want to know how the compiler decided this was ambiguity? while (in my opinion) this should not, because add(short, short) requires two steps of type promotion, and add(byte, long) requires three steps of type promotion .. or do I have a wrong idea ??
java overloading type-promotion
Abd-elrahman adel
source share