Validate method parameter name between interface declaration and implementation

Viewed 42

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.

1 Answers

There is a plugin in the Jetbrains' marketplace that implements this feature. You can find it in this link.

If you want to see the implementation of that plugin, you can take a look at its GitHub's repository.

Related