Eclipse:类型不匹配:无法从 String[] 转换为任何

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10310418/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:05:58  来源:igfitidea点击:

Eclipse: Type mismatch: cannot convert from String[] to any

javascripteclipse

提问by BetaRide

Eclipse is complaining about my JavaScript code:

Eclipse 抱怨我的 JavaScript 代码:

enter image description here

在此处输入图片说明

As fas as I can tell, the code is working fine. What do I have to change to get rid of the warning?

据我所知,代码运行良好。我必须改变什么才能摆脱警告?

回答by machineghost

The semantic validator (despite it's failings, like this one) actually has a lot of uses. For instance, it can tell you when you've got a variable that's not being used anywhere (eg. because you have a typo in the variable's name).

语义验证器(尽管它是失败的,比如这个)实际上有很多用途。例如,它可以告诉您什么时候您有一个没有在任何地方使用的变量(例如,因为您在变量名称中有一个拼写错误)。

If you don't want to see that error message, but you still want to keep semantic validation on, you can use this hack:

如果您不想看到该错误消息,但仍希望保持语义验证,则可以使用以下技巧:

var textArray = 0 || [ ...

it's a little ugly, and your non-Eclipse-using co-workers may not like it, but at least it gives you a way to ditch the warning and still have the benefits of the validator.

它有点难看,您的非 Eclipse 使用同事可能不喜欢它,但至少它为您提供了一种方法来放弃警告并仍然拥有验证器的好处。

A similar hack (if you don't like the first one, or if you're a big Douglas Crockford fan) that will also work is:

一个类似的 hack(如果你不喜欢第一个,或者如果你是 Douglas Crockford 的忠实粉丝)也可以使用:

var textArray;
textArray = [ ...

回答by aleroot

Seems to be a bug of WTP , more specifically of the JS Validator component which is by default configured to "Enable JavaScript semantic validation".

似乎是 WTP 的一个错误,更具体地说是 JS Validator 组件的错误,该组件默认配置为“启用 JavaScript 语义验证”。

Try to turn off the semantic validation from preferences page.

尝试从首选项页面关闭语义验证。