在 Eclipse 中,以下 JavaScript 行
var a1 = [[1, 2], [3, 4]];
生成警告:
Type mismatch: cannot convert from Number[] to any
Type mismatch: cannot convert from Number[] to any
同时
var a2 = [['w', 'x'], ['y', 'z']];
生成:
Type mismatch: cannot convert from String[] to any
Type mismatch: cannot convert from String[] to any
和
var a3 = [[1, 2], ['y', 'z']];
生成:
Type mismatch: cannot convert from Number[] to any
Type mismatch: cannot convert from String[] to any
但是,这些行都可以:
var a4 = [[1, 'x'], [3, 'y']];
var a5 = [[1, 2]];
var a6 = [['x', 'y']];
当子数组包含相同的原始类型时,数组的数组似乎有问题。但是,我不明白为什么,代码似乎执行得很好。谁能解释一下 Eclipse 担心的是什么?
最佳答案
它看起来像一个错误。 Javascript 中基本上不存在类型不匹配这样的事情。
我会冒险猜测执行此操作的解析器是基于 Java 解析器的,这是原始解析器的一部分。
关于javascript - 为什么 Eclipse 有时会对 JavaScript 中的数组数组发出警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7978429/