eclipse 方法必须具有签名“String method() ...[etc]...”但具有签名“void method()”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8083469/
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
Method must have signature "String method() ...[etc]..." but has signature "void method()"
提问by hugri
I have a datatable with a button in each row:
我有一个数据表,每一行都有一个按钮:
<ice:dataTable ... var="item">
<ice:column>
<h:commandButton value="Download" action="#{mybean.downloadItem(item)}" />
</ice:column>
</ice:dataTable>
In the backing bean there's this method:
在支持 bean 中有这个方法:
public void downloadItem(Item item) {
// ...
}
Everything works fine (when clicked the method is executed), but Eclipse validation fails with this strange message:
一切正常(单击该方法时执行),但 Eclipse 验证失败并显示以下奇怪消息:
Method must have signature "String method(), String method(), String method(String), String method(String, String), String method(String, String, String), String method(String, String, String, String), String method(String, String, String, String, String), String method(String, String, String, String, String, String), String method(String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), String method(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)" but has signature "void method()"
方法必须有签名“字符串方法()、字符串方法()、字符串方法(字符串)、字符串方法(字符串、字符串)、字符串方法(字符串、字符串、字符串)、字符串方法(字符串、字符串、字符串、字符串) ,字符串方法(字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串) " 但有签名 "void method()"
What can I do?
我能做什么?
If that's relevant, I'm using Eclipse Indigo SR1 on Tomcat 7.
如果这是相关的,我将在 Tomcat 7 上使用 Eclipse Indigo SR1。
回答by BalusC
Ignore it. Eclipse is a jerk. You can tone it by setting Window > Preferences > Web > JavaServer Faces Tools > Validation > Type Assignment Problems > Method expression signature incompatibilityto Warningor Ignore(it defaults to Error).
忽略它。Eclipse 是个混蛋。您可以通过设置Window > Preferences > Web > JavaServer Faces Tools > Validation > Type Assignment Problems > Method expression signature incompatibilityto Warning或Ignore(默认为Error)来调整它。
Image borrowed from this blogin all courtesy.
礼貌地从这个博客借来的图片。
The reason is, Eclipse expect the action
attribute to always return String
, not void
. Whilst indeed unspecified in JSF action
attribute, the EL method expressions themselves actually also support void
methods. The overzealous message in turn suggests that the underlying logic responsible for this validation is incapable of determining the individual method arguments and thus it tries to compare the raw method signature against a collection of allowed signatures, which ultimately get shown in the message if no match was found. Based on the message, this problem may also disappear when the method has 20 or more arguments ;)
原因是,Eclipse 期望action
属性总是返回String
,而不是void
。虽然在 JSFaction
属性中确实未指定,但 EL 方法表达式本身实际上也支持void
方法。过度热情的消息反过来表明负责此验证的底层逻辑无法确定单个方法参数,因此它尝试将原始方法签名与允许的签名集合进行比较,如果没有匹配,则最终将显示在消息中成立。根据消息,当该方法具有 20 个或更多参数时,此问题也可能会消失;)
This is fixed in Eclipse Luna SR1, nearly 6 years after the issue was reported. The severity has been decreased from Errorto Warning. You may still want to put it yet lower to Ignore.
此问题已在 Eclipse Luna SR1 中修复,距该问题报告已近 6 年。严重性已从Error降低到Warning。您可能仍想将其降低到Ignore。