aspose file tools
The moose likes Beginning Java and the fly likes Assigning values in constructors with varargs Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Assigning values in constructors with varargs " Watch "Assigning values in constructors with varargs " New topic
Author

Assigning values in constructors with varargs

K. Tsang
Ranch Hand

Joined: Sep 13, 2007
Posts: 1222

Hello all, suppose I have the following:



My question is how do I assign the values in the Video class such that there will not be ArrayIndexOutOfBoundsException? Also how can I assign the correct values to the correct variables (eg "xxx" corresponds to videoXXX variable and not videoType variable for vid2)?

Thanks.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12929
    
    3

The varargs variable 'data' behaves like an array inside the constructor. So you can use '.length' just like on any other array to see how many elements it contains.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
Originally posted by K. Tsang:
. . . Also how can I assign the correct values to the correct variables (eg "xxx" corresponds to videoXXX variable and not videoType variable for vid2)?

Thanks.
Using varargs, I think not at all. I think you have demonstrated how unsuitable varargs are for constructors.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
Maybe better to say that varargs are only suitable for setting up arrays, not for individiual members of that array.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Assigning values in constructors with varargs
 
Similar Threads
Servlet request
Using String
Problem with passing variables between methods and classes (I think)
Using Abstract class/methods (cannot find symbol)
inner class question...