Why do we need to specify parameter name in interface?

前端 未结 3 1862
离开以前
离开以前 2021-02-04 00:45

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

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


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-02-04 01:17

    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.

提交回复
热议问题