Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8003575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:41:01+00:00 2026-06-04T16:41:01+00:00

This question is probably going to illustrate a lack of knowledge on my part

  • 0

This question is probably going to illustrate a lack of knowledge on my part about how Groovy classes work, but I have tried to figure this out on my own with no luck. I want to create a getProperty() method on a class so I can reference member variables in a Groovyish way. This is NOT the same as just making them public because I do want some logic done when they are referenced. Basically, I’m trying to create a configuration Groovy class that uses ConfigSlurper:

class Configuration implements GroovyObject {
  private static ConfigObject config  = new ConfigSlurper().parse(new File("testing.conf").toURI().toURL())

  //This method is illegal, but it illustrates what I want to do
  public static String getProperty(String prop){
    config.getProperty(prop)
  }
}

If the above class were legal, I could then reference config items like so:

Configuration.dbUser

instead of this, which would require making the ConfigObject available:

Configuration.config.dbUser

I know, it would be worlds easier to just make the config object public, but knowing how to do this (or know why it’s impossible) would help me understand Groovy a little better.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:41:02+00:00Added an answer on June 4, 2026 at 4:41 pm

    The only way I can get it to work is via the metaClass:

    class Configuration {
      private static ConfigObject config  = new ConfigSlurper().parse( "foo = 'bar'" )
    }
    
    Configuration.metaClass.static.propertyMissing = { name ->
      delegate.config[ name ]
    }
    
    println Configuration.foo
    

    There may be a better way however…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this question has probably been asked before, but i'm stuck and i've tried a
I realize this question has probably been asked numerous times, but I have not
I'm probably going to take some heat for this question. But I'd like to
This is probably going to be more of a discussion or hypothetical question, but
I'm probably going to get abuse for this question but here goes. Oh but
It's a theoretical question at this point in time, but something I'm probably going
this is probably going to seem like a daft question but please bear with
This is probably going to end up as a stupid question, but countless research
This question probably is based on my lack of understanding of the role of
Ok, so this question probably isn't Silverlight specific. I have a silverlight 2 page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.