I would like to ask you whether it is possible in Java to have a method declaration in an interface, but I want certain methods to have a variable number of input parameters (for example, all the same types). I thought something like this:
public interface EqualsCriteria { public boolean isEqual(String... paramsToCheck);
And one class implements the same criteria as, for example:
public class CommonEquals implements EqualsCriteria { private String name; private String surname; .... @Override public boolean isEqual(String otherName, String otherSurname) { return name.equals(otherName) && surname.equals(otherSurname); } }
But maybe I need other criteria in another part of the code, something like this
public class SpecialEquals implements EqualsCriteria { .... @Override public boolean isEqual(String otherName, String otherSurname, String passport) { return name.equals(otherName) && surname.equals(otherSurname) && passport.equals(passport); } }
PS: Actually, my problem is a little more complicated, but it can be useful for me.
source share