Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the @sign do?

Tags:

java

groovy

I have seen the at (@) sign in Groovy files and I don't know if it's a Groovy or Java thing. I have tried to search on Google, Bing, and DuckDuckGo for the mystery at sign, but I haven't found anything. Can anyone please give me a resource to know more about what this operator does?

like image 990
Parham Doustdar Avatar asked Jun 22 '12 07:06

Parham Doustdar


2 Answers

It's a Java annotation. Read more at that link.

like image 133
Josh Avatar answered Sep 26 '22 19:09

Josh


As well as being a sign for an annotation, it's the Groovy Field operator

In Groovy, calling object.field calls the getField method (if one exists). If you actually want a direct reference to the field itself, you use @, ie:

class Test {
  String name = 'tim'

  String getName() {
    "Name: $name"
  }
}

def t = new Test()
println t.name   // prints "Name: tim"
println t.@name  // prints "tim"
like image 25
tim_yates Avatar answered Sep 22 '22 19:09

tim_yates