Simple question about Groovy constructor and @Property

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Simple question about Groovy constructor and @Property

bgoetzmann
Hi,
I've a simple question about this code :

class Test {
  def x
  def y
}

def t = new Test(x: 2)
println t.x

When executed this code returns null ; if I replace "def x" by "@Property x" the code works well and returns "2"

I saw a lot of example using this kind of code like "def t = new Test(x: 2)" but without the use of @Property annotation.
Does the use of the @Property is recent ?

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Simple question about Groovy constructor and @Property

Guillaume Laforge
Administrator
Which version of Groovy do you use?
@Property is deprecated -- outlawed in fact.

On 1/17/07, bgoetzmann <[hidden email]> wrote:

>
> Hi,
> I've a simple question about this code :
>
> class Test {
>   def x
>   def y
> }
>
> def t = new Test(x: 2)
> println t.x
>
> When executed this code returns null ; if I replace "def x" by "@Property x"
> the code works well and returns "2"
>
> I saw a lot of example using this kind of code like "def t = new Test(x: 2)"
> but without the use of @Property annotation.
> Does the use of the @Property is recent ?
>
> Thank you.
>
> --
> View this message in context: http://www.nabble.com/Simple-question-about-Groovy-constructor-and-%40Property-tf3028186.html#a8413279
> Sent from the groovy - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Simple question about Groovy constructor and @Property

tugwilson
In reply to this post by bgoetzmann

On 17 Jan 2007, at 16:19, bgoetzmann wrote:

> Hi,
> I've a simple question about this code :
>
> class Test {
>   def x
>   def y
> }
>
> def t = new Test(x: 2)
> println t.x
>
> When executed this code returns null ; if I replace "def x" by  
> "@Property x"
> the code works well and returns "2"
>
> I saw a lot of example using this kind of code like "def t = new  
> Test(x: 2)"
> but without the use of @Property annotation.
> Does the use of the @Property is recent ?


What version of Groovy are you using?

We deprecated @Property quite a while ago and removed it for Groovy 1.0.

Your example works on Groovy 1.0 here.

def x declares a property x

public x
protected x
private x

all declare fields x



John Wilson
The Wilson Partnership
web http://www.wilson.co.uk
blog http://eek.ook.org



---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Simple question about Groovy constructor and @Property

Daniel Hinojosa
In reply to this post by Guillaume Laforge
Guillaume Laforge wrote:
> Which version of Groovy do you use?
> @Property is deprecated -- outlawed in fact.
Outlawed? Ohhhh, you shouldn't have told me.   Now I want to use it! ;)

>
> On 1/17/07, bgoetzmann <[hidden email]> wrote:
>>
>> Hi,
>> I've a simple question about this code :
>>
>> class Test {
>>   def x
>>   def y
>> }
>>
>> def t = new Test(x: 2)
>> println t.x
>>
>> When executed this code returns null ; if I replace "def x" by
>> "@Property x"
>> the code works well and returns "2"
>>
>> I saw a lot of example using this kind of code like "def t = new
>> Test(x: 2)"
>> but without the use of @Property annotation.
>> Does the use of the @Property is recent ?
>>
>> Thank you.
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Simple-question-about-Groovy-constructor-and-%40Property-tf3028186.html#a8413279 
>>
>> Sent from the groovy - user mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>
>


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Simple question about Groovy constructor and @Property

bgoetzmann
In reply to this post by Guillaume Laforge
Thank you for this information Guillaume,

I used an environment variable that pointed to an older version of Groovy !
The code without @Property is more concise.


Bertrand.

glaforge wrote
Which version of Groovy do you use?
@Property is deprecated -- outlawed in fact.

On 1/17/07, bgoetzmann <bgoetzmann@sophia.symag.com> wrote:
>
> Hi,
> I've a simple question about this code :
>
> class Test {
>   def x
>   def y
> }
>
> def t = new Test(x: 2)
> println t.x
>
> When executed this code returns null ; if I replace "def x" by "@Property x"
> the code works well and returns "2"
>
> I saw a lot of example using this kind of code like "def t = new Test(x: 2)"
> but without the use of @Property annotation.
> Does the use of the @Property is recent ?
>
> Thank you.
>
> --
> View this message in context: http://www.nabble.com/Simple-question-about-Groovy-constructor-and-%40Property-tf3028186.html#a8413279
> Sent from the groovy - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: Simple question about Groovy constructor and @Property

Jochen Theodorou
In reply to this post by bgoetzmann
bgoetzmann schrieb:

> Hi,
> I've a simple question about this code :
>
> class Test {
>   def x
>   def y
> }
>
> def t = new Test(x: 2)
> println t.x
>
> When executed this code returns null ;

that's not 1.0 then.

> if I replace "def x" by "@Property x" the code works well and returns "2"
>
> I saw a lot of example using this kind of code like "def t = new Test(x: 2)"
> but without the use of @Property annotation.
> Does the use of the @Property is recent ?

@Property was for many releases a way to mark a field as property. Now
everything without visibility modifier is a property. @Property is now
outlawed due to the coming use of "real" annotatons. But @Property was
there for... I don't know, but I am sure it was at last a year

bye blackdrag

--
Jochen "blackdrag" Theodorou
Groovy Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email