Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cant compile code with var-args

 
P Teng
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't get a code with a method containing var-arg to compile.

System.getProperty("java.version") in the code returns 1.5.0_10

what could be wrong ?

Method signatute is as below

static void aMethod (String... y)
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the compiler output?
 
Campbell Ritchie
Sheriff
Posts: 48921
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Have you got a space before the ... ? It might require a space.
Have you got a method whose signature only differs by having [] instead of ... ? If so, the compiler will interpret those two signatures as identical and fail to compile.
Execute this command javac -version at the command line to confirm which version of compiler you have in your PATH.
 
P Teng
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, it must be one of the PATH settings or the version. The same code works at home. Thanks Ritchi ! Hope to hear/tell/learn lot more in the forum in the future.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic