Hi,
I need to add multiple entries of my PhoneNumber(number,type) to my main Person(name,PhoneNumber) object.
Can I use varargs for working this out or is there a better and more efficient way to do it??
I am trying to work it as follows:
// number is a String and type is an enum
PhoneNumber [] numbers = {
new PhoneNumber(number , type),
new PhoneNumber(number,type),
new PhoneNumber(number,type),
};
class Person(){
Person(String name, PhoneNumber...numbers){
// adding all the phonenumber objects to a list for each person.
}
I am not sure if this is the correct way to implement it and whether varargs is the best option?
Please advise. I know its a basic java question but was not finding a better solution to above problem.