Issue:
public interface ITest
{
String JoinString(String first, String second);
}
public class Test implements ITest
{
@Override
public String JoinString(String first, String second)
{
return first + second;
}
}
public class Main
{
public static int Main(Object[] args)
{
var inst = (ITest) new Test();
inst.JoinString("a", "b");
}
}
This correctly returns string "ab". But if you change the interface and swap the parameters
public interface ITest
{
String JoinString(String second, String first);
}
then the method still returns "ab" instead of expected "ba". This expectation is based on the parameter name "first" and "second".
Question: How do you validate that parameter names from interfaces match the names in implementation? Preferably during build time with a build error.
In newer IntelliJ versions, this is under Editor->Inspections->Java->Naming conventions->Parameter name differs from parameter in overriden or overloaded method - no need for external plugins anymore for this: