Enforcing parameter name consistency

NWS :

In the following trivial example an interface is created, with a method & parameter name bar.

The following implementation subtly changes this legally by specifying zoo.

    public class Query {

      public interface MyInterface {
        public void foo(int bar);
      }

      public class Thing implements MyInterface {
        @Override
        public void foo(int zoo) { }   
      }

      public Query() { }

      public static void main(String[] args) { }

    }

How can i force the parameter name to conform to what was specified in MyInterface (bar not zoo)?

Ideally i am looking for a compiler option or similar that would throw a warning or error.

m.antkowicz :

On compiler level (e.g. javac) - you cannot, the method signature is being create only from the method name and parameters types so the names and return type are basically ignored

The only you can do is to write your own syntax rule for tools like SonarQube but as far as I understand it won't be suitable for you.

Seems that you want to create some library [code serializing?] and force user to use proper parameter naming - that means that you would need to force him to use specific tool also

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=136238&siteId=1