Barodapride Barodapride - 1 month ago 5
Groovy Question

Accessing Groovy properties or methods

I have a simple question. If I have an

HttpResponseDecorator
(
groovyx.net.http.HttpResponseDecorator
) how come I can do
response.status
to get the response code? When I'm debugging I don't see this property available in the object. I looked up the API and I don't see the status property available. How is
response.status
working? Am I missing a language feature?

Answer

The Groovy property is a combination of a private field and getters/setters. Groovy will then generate the getters/setters appropriately.

For example:

class Person {
    String name                             
    int age
}

Properties are accessed by name and will call the getter or setter transparently. I would recommend read more in the Groovy documentation for field and properties.

Comments