Search code examples
javainterfaceparametersnamed-parameters

Why do we need to specify parameter name in interface?


When we create interface methods, can't we do something like in java:

void interface_method(Integer,String, /* other parameter */);

Instead I noticed that we also need to give the parameter names lile:

void interface_method(Integer i, String s);

Also the interface implementor don't need to have the same parameter name as in interface method.

I found a similar question about c# over here . They mention one scenario of named parameter but I don't find any other relevent reason specifically in java.


Solution

  • From a technical standpoint it wouldn't be necessary.

    I've always taken it as a syntax normalization, and a documentation aid.

    This way there's:

    1. No reason to differentiate between class and interface method syntax, and
    2. Default Javadoc documentation can be generated using the (descriptive!) parameter name.