Passed: SCJP 6 (90%), SCJD 6
Other: Spring training, extensive Swing experience
Brian Spindler wrote:
...
but as soon as you try to call one of these methods like so:
it fails to compile because it's ambiguous.
HTH.
SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
SCJP 5 ๑۩۞۩๑♥~~ My Life is My Creation ~~♥๑۩۞۩๑
Bob Wheeler wrote:
Hi,
now i don't understand that. For m(1) to match void m(Integer... i) {} it needs to autobox it.
But for the other method void m(int... i) {} it doesn't need it. So this is the wrong way to look at it ?!
So, because the autoboxing is done automatically it is ambiguous? No, if var-args is not used all is fine.
So the reason is the var-args. But why? Can anybody explain.
Thanks for any help
Bob
because null can be assigned to both methods arguments
but String and MangoShake are not in same hierarchy.
SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
Passed: SCJP 6 (90%), SCJD 6
Other: Spring training, extensive Swing experience
John McParland wrote:It doesn't work with var-args because var-args is a short-hand way of saying int[] (or some other array).
An array is a subclass of Object so you can't combine boxing and var-args too simply;
WIDENING beats BOXING
BOXING beats VAR-ARGS
Are rules to remember. But there is no rule to say whether boxing should take place or not when deciding which var-args method to use.
SCJP 6 - SCJD - SCWCD 5 - SCBCD 5
JavaEnterpriseEditionFaq - TomcatFaq
All code in my posts, unless a source is explicitly mentioned, is my own.