Today I was writing a function that had two required arguments and three optional arguments. Since using Optional<>
types is frowned upon as arguments, function overloading has been my tool to handle this. So I end up with something like this:
public boolean func(int a, String b)
public boolean func(int a, String b, String c)
public boolean func(int a, String b, int d)
public boolean func(int a, String b, long e)
Then I have to do the various combinations of two arguments...
public boolean func(int a, String b, String c, int d)
public boolean func(int a, String b, String c, long e)
public boolean func(int a, String b, int d, long e)
and finally the "full function"
public boolean func(int a, String b, String c, int d, long e)
This seems like too much work to me, and when that happens I feel like im doing something wrong. Why should I be creating 7 additional functions instead of using an Optional
or a POJO in this case? What is the most efficient way to handle this?