从Classic到JSR的语法升级

此处只是一个变化的核对清单,通过它你可以确保你的Groovy classic codebase跟新的Groovy JSR在语法上兼容。

安全导航

在Classic的Groovy 我们常常使用这样的语法:

class Person = { String name }
y = null
println "${y->name}"    // -> was the optional gpath operator with Classic Groovy syntax

通过安全导航,我们可以避免NullPointerException,但需要使用”?.”操作符来替代箭头(->)操作符。

新的JSR语法是

class Person = { String name }
def y = null
println "${y?.name}"    // Now, ?. is the optional gpath operator the new Groovy JSR

闭包的参数分隔符语法

 
wiki/user_guide/migration_from_classic_to_jsr_syntax.txt · 最后更改: 2008-04-19 13:50 (外部编辑)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki