简体   繁体   English

为什么在接口的方法中声明“ VariableDeclaratorId期望”?

[英]Why is “VariableDeclaratorId expected” in declaring methods in an interface?

when you're creating an interface, why do you have to give the Variable ID's ? 创建接口时,为什么必须提供变量ID? You're just making an interface which is essentially a contract. 您只是在创建一个本质上是合同的接口。

Why can't my method me like this: 为什么我的方法不能像这样:

method(int);

and has to be 并且必须

method(int x);

We are not implementing the methods. 我们没有实现这些方法。 I don't see the use of the x here. 我在这里看不到使用x。

In theory, there is no need for parameter names in interfaces, but because that is how methods are generally defined, and has become a requirement. 从理论上讲,不需要在接口中使用参数名称,但是因为这是方法的一般定义方式,因此已成为一种要求。

It also makes the code a lot more readable and maintainable. 这也使代码更具可读性和可维护性。 If there were 5 integers in a row, you would implement that class and have no clue what each of them mean. 如果连续有5个整数,则将实现该类,并且不知道它们各自的含义。 Even a descriptive method name would not be able to clue you in on that. 即使是描述性的方法名称也无法为您提供线索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM