| Author |
var-args doubt...
|
Ganeshkumar cheekati
Ranch Hand
Joined: Oct 13, 2008
Posts: 362
|
|
public class TestVargs { public static void main(String[] a) { TestVargs t=new TestVargs(); t.doStuff(1); t.doStuff(1,2); } public static void doStuff(int... w) { System.out.println("int w"); } public static void doStuff(int i,int... ae) { System.out.println("int i,int.. ae"); } } when i compile the above code in java1.5 it s displaying two errors: one is:<identifier expected> public static void doStuff(int... w) ^ second is:<identifier expected> } ^ what is the problem?
|
SCJP5 and SCWCD1.5
Think Twice Act Wise...
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
Because compiler is unable to match one method since both methods defined in the class matches
t.doStuff(1); t.doStuff(1,2);
method invocations.
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
subhasish nag
Ranch Hand
Joined: Apr 25, 2008
Posts: 101
|
|
|
As the compiler unable to determine which method to be called it will throw compiler error.
|
Thanks,<br />Subhasish
|
 |
Ganeshkumar cheekati
Ranch Hand
Joined: Oct 13, 2008
Posts: 362
|
|
|
even if i am compiling with only first method(no second method) the same errors are coming..
|
 |
subhasish nag
Ranch Hand
Joined: Apr 25, 2008
Posts: 101
|
|
There is no compiler error. You are compiling with jdk1.4 ,that is the problem [ October 27, 2008: Message edited by: subhasish nag ]
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
Well I tried the code and with both the method, it gives ambiguity error not identifier expected. If you remove the second method, then there is no compilation error...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Ganeshkumar cheekati
Ranch Hand
Joined: Oct 13, 2008
Posts: 362
|
|
public class TestVargs { public static void main(String[] a) { TestVargs t=new TestVargs(); t.doStuff(1); //t.doStuff(1,2); } public static void doStuff(int... w) { System.out.println("int w"); } } the above also giving 2 compilation errors as <identifier expected>. i installed J2SE5.0 Update 16 in my system and i set classpath to "C:\Documents and Settings\Administrator\java5\lib;.; ". could you tell me how can i check version which i am using right now in command prompt. [ October 27, 2008: Message edited by: Ganeshkumar cheekati ]
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
could you tell me how can i check version which i am using right now in command prompt.
Just type java -version in the command prompt. You will get the version you are using (in fact it uses the first entry in the path variable if you have more than one defined). By the way you have to set the path environment variable to bin folder of your java installation not the classpath. [ October 27, 2008: Message edited by: Vijitha Kumara ]
|
 |
Ganeshkumar cheekati
Ranch Hand
Joined: Oct 13, 2008
Posts: 362
|
|
|
hi subhasish nag.thanku so much.
|
 |
subhasish nag
Ranch Hand
Joined: Apr 25, 2008
Posts: 101
|
|
|
welcome Ganesh.
|
 |
 |
|
|
subject: var-args doubt...
|
|
|