【发布时间】:2015-07-01 18:36:00
【问题描述】:
Groovy 中的简单泛型类
@CompileStatic
class Foo<T> {
T member
}
还有一个适用于双打列表的特定子类。很简单,对吧?
@CompileStatic
class DoubleListFoo extends Foo<List<Double>> {
void bar() {
println member.size()
}
}
不会在 Maven 中编译:
[ERROR] DoubleListFoo.groovy:[12,9] 3. ERROR in DoubleListFoo.groovy (at line 12)
[ERROR] println member.size()
[ERROR] ^^^^^^^^^^^^^
[ERROR] Groovy:[Static type checking] - Cannot find matching method java.lang.Object#size(). Please check if the declared type is right and if the method exists.
从 IntelliJ 中编译得很好。怎么回事?
Maven 版本:
mvn -version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T13:58:10-07:00)
Maven home: /usr/local/apache-maven-3.2.3
Java version: 1.7.0_71, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"
Groovy 版本:
groovyc -version
Groovy compiler version 2.4.3
Copyright 2003-2013 The Codehaus. http://groovy.codehaus.org/
FWIW,这是一个简单的测试用例,当一个更复杂的类无法编译并出现错误“无法将 T 类型的值赋给 double[] 类型的变量”时。
【问题讨论】: