Why widening beats both Boxing and var-args in Overloading of a method?

前端 未结 7 2326
不知归路
不知归路 2020-12-06 13:03

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. Tri

7条回答
  •  甜味超标
    2020-12-06 13:15

    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.

提交回复
热议问题