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
I don't know about you, but I'd much rather that the compiler passed my byte
as an int
than as a Byte
. Consider the overhead. And varargs also requires boxing.
In other words, the reason is efficiency. The language design prefers the more efficient calling mechanism that does not require it to allocated a boxed item.
'Requires', you ask? The varargs functions expect to get an array of Object
, and that can't include a primitive type.
Compatibility is not a bad reason, either.