I have admittedly the following poorly implemented class:
public class Fari{
String name;
String[] group;
public Fari(String name, String... group) {
this.name = name;
this.group = group;
}
// getters, setters
}
This was actually planned in such a way that the name and at least one group label is passed. But i can create a new Fari object with only one parameter without a compile erorr:
Fari f = new Fari("A");
ending in an object with null for the group attribute. Is there a way to force that at least one string should be passed as the varargs parameter?
I could change the parameter String... group
to a List<String>
but then I have to touch all other classes as well. Apart from that an empty list could be passed, which doesn't really help me. How do I go about this if the created object should have a name and at least one group lable?