为什么我们需要在接口中指定参数名称? [英] Why do we need to specify parameter name in interface?

查看:332
本文介绍了为什么我们需要在接口中指定参数名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们创建界面方法时,我们不能像 java 那样做:

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

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

相反,我注意到我们还需要给出参数名称lile:

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

void interface_method(Integer i, String s);

此外,接口实现者不需要具有与interface方法相同的参数名称。

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

我发现了一个类似的关于c#的问题这里。他们提到了命名参数的一个场景,但我没有在java中找到任何其他相关的相关原因。

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.

推荐答案

从技术角度来看,没有必要。

From a technical standpoint it wouldn't be necessary.

我一直把它作为语法规范化和文档辅助。

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

这种方式有:


  1. 没有理由区分类和接口方法语法,
  1. No reason to differentiate between class and interface method syntax, and
  2. Default Javadoc documentation can be generated using the (descriptive!) parameter name.

这篇关于为什么我们需要在接口中指定参数名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆