1
我在常规下面的代码:Groovy的CompileStatic与泛型列表
class Test {
List<Integer> yo(boolean x) {
List<Integer> res = x ? [] : [1, 2, 3]
}
}
它编译很好,直到我添加@CompileStatic
批注类。然后编译失败
Test.groovy: 5: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.List <? extends java.lang.Object> to: java.util.List <Integer>
@ line 5, column 27.
List<Integer> res = x ? [] : [1, 2, 3]
难道真的预期的Groovy不能推断泛型类型的空单[]
的?
'[]'有iferred类型'名单
在这种特殊情况下,有一个'List'类型的LHS,我以某种方式预计'[]'是同一类型的...因为'列表 l = []'确实有效...... –
Nikem
这看起来像Groovy的bug。 – Dany