I am preparing for a SCJP exam and when studying widening part it’s given that widening beats both Boxing and Var-args in overloading but there is no clear explanation. Tried searching but didnt get any better answer.
One answer i got is because the compiler chooses the older style before it chooses the newer style. But I am not convinced.
Edit: I know widening is preferrd than boxing and var-args. but WHY is my question. of which i know one. any other reasons.
Yes, the compiler “chooses the older style over the newer style”, because of compatibility requirements. Imagine some code, written before Java 5 came out, that suddenly had a change of behaviour when compiled under Java 5! That would be bad.
Widening conversions have been around since the dawn of Java, but autoboxing and varargs are new to Java 5.