Why do we need to specify parameter name in interface?

限于喜欢 提交于 2019-12-02 22:11:17

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.

Without parameter names it becomes very hard to distinguish between parameters of the same type.

double divide(double, double);

Convention says that the second parameter would be the divisor. But with named parameters, it is explicit and much clearer. In turn, the documentation can clearly use the names instead having to continually say "first parameter" or "second parameter" when trying to explain how the method should be use and what each parameter is meant to represent.

My take on this:

  1. This is in language specification for parameters to have names;

  2. Interface being interface, names help to communicate the meaning;

  3. Interface is not really a forward declaration of implementation that will follow like in C/C++, so comparison is not entirely correct;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!