I want to force the user to fill in an optional parameter when calling my constructor:
public MyClass(String... params) {
this.params = params;
}
Currently, the following code is valid:
new MyClass();
I want to prevent it. I thought of this:
public MyClass(String param1, String... otherParams) {
this.params = new String[1 + otherParams.length];
this.params[0] = param1;
// fill 1..N params from otherParams
}
String[] params
is not an option, because I need the ability to use comma separated args.
Are there any nice solutions to achieve this? Please don't say that varargs parameters must be optional. The question is not about that.