• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

var-args doubt...

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi subhasish nag.thanku so much.
 
subhasish nag
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
welcome Ganesh.
reply
    Bookmark Topic Watch Topic
  • New Topic