Details
-
Type:
Sub-task
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.7.6
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:Linux, Fedora 13, Vaio F12
-
Number of attachments :
Description
As per this thread on Groovy User:
http://groovy.329449.n5.nabble.com/Cannot-create-static-property-via-metaClass-td3792536.html#a3832577
I am unable to do the following:
class Foo {}
Foo.metaClass.static.bar = 1
Foo.bar // error, no such property bar for class Foo
Suggested non-working workaround:
class Foo {}
Foo.metaClass.static.getBar =
Foo.metaClass.static.setBar =
println Foo.bar // 1
Foo.bar = 5
println Foo.bar // obviously, still 1 since static bar property is never created, just creating static getter/setter for a non-existent foo
Interestingly, running above code once, and then swapping getBar=
{1}with getBar=
{bar}, the code works and one can overwrite the initial value.
On a side note: when we are able to create an MCL static properties, what will the scope be? i.e. same as
class Foo
I ask because I am unsure where groovy MOP and JVM garbage collection come into play. I stumbled across this problem as I was attempting to create a per request singleton (via MCL), as opposed to application/instance lifetime scoped with
class Foo
Thanks for evolving Groovy, now & the future are very bright.
I this is assigned to the wrong components (Component/s: Groovlet / GSP, Groovy Console).