I would like to create a method that will, sometimes have two arguments passed to it, but only one at other times without passing a null
(empty) argument. I know I could do method overloading, but I was looking for a feature like below, without the need for iteration later on:
class MyObject {
int id;
int[] zero_Or_MoreArguments;
Animal(int id, int... zero_Or_MoreArguments) {
this.id = id;
this.zero_Or_MoreArguments = zero_Or_MoreArguments;
}
}
Is there such a thing in Java? Do I have any options here? Thanks in advance.