Groovy @ symbol before fields

断了今生、忘了曾经 提交于 2019-12-03 01:14:36

It allows you to override groovy's use of property accessors. If you write:

println u.name

groovy will invoke the automatically generated getter Person.getName(). If you write:

println u.@name

it will go directly to the field like it would in Java. In the case of the closure, it seems to have a first field but not a corresponding getFirst accessor.

In the groovy manual, it's documented as the direct field access operator.

It means you're accessing a field directly, rather than going through a getter.

See the Groovy operator docs, although there isn't much more to say. Other than probably avoid it.

The reason it fails for a ComposedClosure is because there's no getter for first (or second).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!