Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of ".@ " in groovy?

Tags:

groovy

What is the use of .@ in groovy? Can anyone explain me with a code snippet?

like image 268
Ant's Avatar asked Jun 20 '11 06:06

Ant's


2 Answers

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

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

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

like image 116
Tomasz Nurkiewicz Avatar answered Sep 22 '22 04:09

Tomasz Nurkiewicz


That's the Java Field operator (according to the documentation)

There are examples in the documentation.

It is also used for accessing attributes when you are parsing XML (again, there's an example if you follow that link).

like image 30
tim_yates Avatar answered Sep 22 '22 04:09

tim_yates