我是 groovy 的新手,我正在阅读gretty项目的源代码
import org.codehaus.jackson.map.ObjectMapper
class JacksonCategory {
static final ObjectMapper mapper = []
...
}
我看不懂代码ObjectMapper mapper = []
,这里是什么[]
意思?我以为它是 a list
,但是如何将它分配给 a ObjectMapper
?
更新
就看沙丘的回答了,好像[]
是手段invocation of default constructor
。所以,这意味着:
static final ObjectMapper mapper = new ObjectMapper()
但:
String s = []
println s // -> it's `[]` not ``
和
Integer i = []
抛出异常:
Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[]'
with class 'java.util.ArrayList' to class 'java.lang.Integer'
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[]' with class
'java.util.ArrayList' to class 'java.lang.Integer'