jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
groovy
  • groovy
  • GROOVY-2503 MOP 2.0 design inflluencing issues
  • GROOVY-4730

Cannot create static property via metaClass

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Sub-task Sub-task
  • Status: Open Open
  • Priority: Major 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 :
    0

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 =

{ 1 }


Foo.metaClass.static.setBar =

{ Integer x->bar=x }


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

{ static bar }

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

{ private static final bar = new Thing() }

Thanks for evolving Groovy, now & the future are very bright.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Pascal Schumacher added a comment - 01/Jan/13 3:21 AM

I this is assigned to the wrong components (Component/s: Groovlet / GSP, Groovy Console).

Show
Pascal Schumacher added a comment - 01/Jan/13 3:21 AM I this is assigned to the wrong components (Component/s: Groovlet / GSP, Groovy Console).
blackdrag blackdrag made changes - 04/Jan/13 8:39 AM
Field Original Value New Value
Component/s Groovlet / GSP [ 11660 ]
Component/s Groovy Console [ 13412 ]
blackdrag blackdrag made changes - 04/Jan/13 8:40 AM
Parent GROOVY-2503 [ 61571 ]
Issue Type Bug [ 1 ] Sub-task [ 7 ]
Hide
Permalink
blackdrag blackdrag added a comment - 04/Jan/13 8:40 AM

I made this a child for the MOP2 task and removed the components

Show
blackdrag blackdrag added a comment - 04/Jan/13 8:40 AM I made this a child for the MOP2 task and removed the components

People

  • Assignee:
    Unassigned
    Reporter:
    James Lang
Vote (0)
Watch (2)

Dates

  • Created:
    17/Mar/11 12:28 AM
    Updated:
    04/Jan/13 8:40 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.