java - Varargs for adding multiple object instances -


I need to add the number (number, type) of my phone number to my main person (name, phone number) object is.

Can I use Varargs to do this work or is there a better and more efficient way to do it ??

I am trying to work it out:

  // is a string and type an enum PhoneNumber [] number = {new PhoneNumber (number, type) , New PhoneNumber (number, type), new PhoneNumber (number, type),}; Class person () {person (string name, phone number ... number) {// Adding all phone numbers to each phone in the list}  

I'm not sure that this Is this the right way to apply and what is the best option?

Please advise. I know its original Java question but the problem above is not getting better solution.

I wonder, where do these phone numbers come from? It is unlikely that those phone numbers will appear in the correct source code. I mean, do you really think that someone can actually write something like a real life code in new person ("arthur", phoneNo1, phoneNo2, phoneNo3) ?

I 'does not look like (OK, such code can be displayed in a unit-test, but not in the' real 'code). Those notifications come from a configuration file, or any action from the user, or from a stream from a network, anything. In any case, if the phone number comes in one, or in some type of archive , then I will give you a method Add Phononumber (PhoneNumber N) , and an option Suggestions for addAllPhoneNumbers (Collection & Phone; )

I suggest that the latter method can be added only when you need it, or if you know to make sure that it will be helpful it is just a convenient way. , absolutely.

I think that classgroups are only useful when the developer has the potential to write method call by hand ( String.format is a suitable use of varargs).


Comments