为什么在方法的重载中加宽Boxing和var-args? [英] Why widening beats both Boxing and var-args in Overloading of a method?

查看:133
本文介绍了为什么在方法的重载中加宽Boxing和var-args?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正准备参加SCJP考试,在学习拓宽部分的时候,考虑到加宽超过Boxing和Var-args,但是没有明确的解释。尝试搜索但没有得到任何更好的答案。

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.

编辑:我知道扩大比拳击和var-args更喜欢。但为什么是我的问题。其中我知道一个。任何其他原因。

I know widening is preferrd than boxing and var-args. but WHY is my question. of which i know one. any other reasons.

推荐答案

是的,由于兼容性要求,编译器选择旧样式而不是新样式。想象一下在Java 5出现之前编写的一些代码,它们在Java 5下编译时突然发生了行为变化!这将是糟糕的。

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.

自Java诞生以来,扩展转换已经存在,但自动装箱和varargs是Java 5的新功能。

Widening conversions have been around since the dawn of Java, but autoboxing and varargs are new to Java 5.

这篇关于为什么在方法的重载中加宽Boxing和var-args?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆