SCJP 6.0 (86%) SCWCD 5 (94%)
saima kanwal wrote:Why is the compiler confused?? can anyone clarify ??
SCJP 6.0 (86%) SCWCD 5 (94%)
saima kanwal wrote:why?? does it mean that it should take an array of ints ??
saima kanwal wrote:if so then why does it work for a single or multiple int values without the array curly braces (when not overloaded)?
Let's look at some legal and illegal var-arg declarations:
Legal:
void doStuff(int... x) { } // expects from 0 to many ints as parameters
....
..
....
SCJP 6.0 (86%) SCWCD 5 (94%)
saima kanwal wrote:what does it mean ?? int values or an array of int??
SCJP 6.0 (86%) SCWCD 5 (94%)
saima kanwal wrote:According to my understanding, when i write :
doStuff(i) // i am passing an int value
and when i write
doStuff(new int[]{1,2,3}) or
int arr = {1,2,3};
doStuff(arr)
I am passing an int array.
According to my understanding, when i write :
doStuff(i) // i am passing an int value
and when i write
doStuff(new int[]{1,2,3}) or
int arr = {1,2,3};
doStuff(arr)
I am passing an int array.
SCJP 6.0 (86%) SCWCD 5 (94%)
saima kanwal wrote:
I want to understand the concept of var-arg , that is what i have been asking here for. I want to know why does the compiler accepts both the cases , though according to me both have different meaning :passing int values like doStuff(10,20) and passing an array like doStuff(new int[]{1,2,3}) .
SCJP1.6,SCWCD1.5
It is still true that multiple arguments must be passed in an array, but the varargs feature automates and hides the process.
The three periods after the final parameter's type indicate that the final argument may be passed as an array or as a sequence of arguments.
Paper beats rock. Scissors beats tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|