• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Query on var-args in java

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to use var-args in method as parameter. Signature of the method is as below

public void method(int age, String name, int... marks)

Above method is not compiling in 1.6 and giving the message as "Syntax error, varargs are only available if source level is 1.5". Below are the queries regarding this

1) Is var-args supported in 1.5 only?
2) If yes what is the reason to remove this feature in 1.6?
3) As its not supported in 1.6, are the questions on var-args still being asked in 310-065 exam?

Also please post var-args related scjp question which you have come across.

Thanks in advance!!!
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they are supported in 1.6.....
can you post the exact program that you tried compiling
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the command line, type:

java -version

What does that put out? I'm just checking to make sure you have 1.5 or greater.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe you're using Eclipse, if so i had the same observation.
You should modify the version in the menu of Eclipse:
Window->Preferences->Java->Compiler
You can do it for a project only or for all projects.

Maybe this can help.

 
Bhaskar Joshi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All!

Yes I used Eclipse 3.5.1 and I was using 1.6 compiler. After changing it to 1.5 , error gone.

Below is the program which I tried to compile.

/**
* Problem Statement: Try the combination for var args
*/
package book.kathy.chapter01;

/**
* @author Amol Choudhari
*
*/
public class VarArgsInMethod {

/**
*
*/
public VarArgsInMethod() {
// TODO Auto-generated constructor stub
}

public void method(int age, String name, int... marks) {

}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}
 
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works perfectly fine with my eclipse though my compliance level is 1.6
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhaskar please Use Code Tags when you post a source code. That way your code looks formatted. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your message using button and then add code tags to it...
 
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic