Results 1 to 5 of 5
Thread: varargs issue
- 03-06-2011, 11:45 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 24
- Rep Power
- 0
varargs issue
I thought I understood how it works after Junkey helped me out. Turns out I didn't. I typed this code in and got an error.
Are you not allowed to use two varargs like that? If not, then I cannot use them with my constructors since I need to know the amount as well as the ingredient names.
The orginal thread, with the conversation between Junkey and I is here. (If you need a reference to see what I was doing).
Simple question
Java Code:Recipe(String... args, int... args2) { }missing method body, or declare abstract
')' expected
<identifier> expected
cannot find symbol
symbol: class args2
<identifier> expected
- 03-07-2011, 12:48 AM #2
My bad, I didn't fully explain. You can only use one varags in a parameter list and it must be the last parameter.
- 03-07-2011, 12:49 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 24
- Rep Power
- 0
Oh ok, I was kind of thinking that might of been so since I couldn't get it working. :S So I guess I am stuck with all those separate constructors then? Unless you know something super cool like those other two things. :).
- 03-07-2011, 01:25 AM #4
You could create an Ingredient class, create a bunch of Ingredient objects and pass them to the Recipe class.
- 03-07-2011, 01:27 AM #5
Member
- Join Date
- Mar 2011
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Same issue as before....
By hayden06f4i in forum New To JavaReplies: 4Last Post: 11-08-2010, 01:49 AM -
the strangeness of Varargs...
By vlad in forum New To JavaReplies: 6Last Post: 05-10-2010, 05:05 PM -
the strange and weird world of Varargs...
By vlad in forum Advanced JavaReplies: 2Last Post: 05-09-2010, 12:29 AM -
VarArgs Example
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks