Overloading for optional array support - Java -


is there way make code more concise not have many overloaded methods?

public void method(string[] args1, string[] args2){} public void method(string[] args1, string args2){} public void method(string args1, string[] args2){} public void method(string args1, string args2){} 

the number of overloaded methods increases exponentially number of arguments increases. problem, , know there has easier way this.

the goal find best way pass number of objects of same type argument without using array single-object input.

why? it's simplicity end programmer.

maybe if have great number of arguments - besides - can increased in future, it's better wrap them in separate class, i.e. inputparams , pass 1 instance of class method. consider next code:

inputparam ip = new inputparam(); ip.setfield1(field1); //... // usage this.method(ip);  // declaration public void method(inputparams arg){} 

p.s. but, other guys mentioned, depends on many conditions , trying achieve.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -