Results 1 to 3 of 3

Thread: Vararg's error.

  1. #1
    MustSeeMelons is offline Member
    Join Date
    Oct 2012
    Posts
    38
    Rep Power
    0

    Default Vararg's error.

    Hi.
    Im having a problem when trying to use varargs when passing them to the constructor.
    This is the constructor, seems ok to me and to the compiler, but when trying to create an object with this constructor, it says that no such constructor exists. Is the syntax wrong? For example:
    Staff S1=new Staff("John", "Box", "Manager", 655, 2,3,"a","b","c");

    Java Code:
    public Staff(String firstName, String lastName, String jobTitle, int ID, int level, String...strings)
    		{
    			super(firstName,lastName,jobTitle,ID,level);
    			setSkills();
    			setSkill(strings);
    		}
    Java Code:
    public void setSkill(String...strings)
    		{
    			for(String element:strings)
    			{
    				skills[skillCount()]=element;
    			}
    		}
    Java Code:
    String skills[];
    		public void setSkills()
    		{
    			skills=new String[3];
    		}

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Vararg's error.

    The constructor needs two integers (int ID, int level), you are trying to pass three integers ( 655, 2,3) ?

  3. #3
    MustSeeMelons is offline Member
    Join Date
    Oct 2012
    Posts
    38
    Rep Power
    0

    Default Re: Vararg's error.

    Well, now im embarrassed, thank you for pointing that out.
    Worst first post ever. o_O

Similar Threads

  1. Replies: 3
    Last Post: 05-08-2012, 05:26 PM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 3
    Last Post: 01-23-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •