What is the ". @" In groovy?

What is the use of .@ in groovy? Can someone explain the code snippet to me?

+7
source share
2 answers

This is a Java field operator ( as per documentation )

There are examples in the documentation.

It is also used to access attributes when parsing XML (again, if you follow this link).

+6
source

Have you seen the official documentation ? It contains good code samples.

Essentially when you use the normal operator . , you indirectly touch the fields using implicitly created getters / setters. However, .@ allows you to access the field directly by skipping the getter / setter.

This can be useful if you want to avoid some additional logic implemented in getter / setter and directly change the field. It violates tons of OOP principles, but Groovy authors find this construct useful.

+9
source

All Articles