Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

var-args doubt...

 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
subhasish nag
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the compiler unable to determine which method to be called it will throw compiler error.
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even if i am compiling with only first method(no second method) the same errors are coming..
 
subhasish nag
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi subhasish nag.thanku so much.
 
subhasish nag
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
welcome Ganesh.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic