Groovy中var关键字的用法

6l7fqoea  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(64)

Groovy文档:* 变量可以使用它们的类型(如String)或使用关键字def(或var)后跟变量名来定义,defvar用作类型占位符,即当您不想给予显式类型时,类型名的替换:*

String x
def y
var z

字符串
但是当我尝试使用var时,例如:

var blah = 'ha?'


我得到一个例外:

Caught: groovy.lang.MissingMethodException: No signature of method: statements.var() is applicable for argument types: (java.lang.String) values: [ha?]
Possible solutions: wait(), run(), run(), every(), any(), wait(long)


Groovy var关键字有什么用?

xam8gpfp

xam8gpfp1#

var可以在Groovy 3+(Java 8+)中使用

相关问题