Java 错误 - 实际和形式参数列表的长度不同
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22813484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Error - Actual and formal argument lists differ in length
提问by Dee
I am trying to call a method, but it is giving this error:
我正在尝试调用一个方法,但它给出了这个错误:
java:112: error:required:String, String
found:String
reason:actual and formal arguments lists differ in length
java:112: 错误:必需:字符串, 字符串
找到:字符串
原因:实际和形式参数列表的长度不同
Here is the method I'm trying to call:
这是我试图调用的方法:
public void setShippingDest(String inCustName, String inDestn) {
// ...
}
Here is how I'm trying to call it:
这是我试图称呼它的方式:
shipOrder.setShippingDest("Broome");
采纳答案by Jon Skeet
Well it's quite simple. Here's the declaration of setShippingDest
:
嗯,这很简单。以下是声明setShippingDest
:
public void setShippingDest(String inCustName, String inDestn)
And here's how you're trying to call it:
这是您尝试调用它的方式:
shipOrder.setShippingDest("Broome");
You've provided one argument, but there are two parameters? How do you expect that to work? You either need to provide another argument, or remove one parameter.
您提供了一个参数,但有两个参数?你希望它如何运作?您要么需要提供另一个参数,要么删除一个参数。
(I'd also strongly advise that you remove the in
prefix from all of your parameters, and look into a real unit testing framework such as JUnit, rather than writing an enormous main
method.)
(我还强烈建议您in
从所有参数中删除前缀,并查看真正的单元测试框架,例如 JUnit,而不是编写庞大的main
方法。)
回答by Jayanth
Also if you like to specify only the Customer Name, you could do so by overloading the method as
此外,如果您只想指定客户名称,则可以通过将方法重载为
public void setShippingDest(String inCustName)
{
return setShippingDest(inCustName, defaultvalue1);
}