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 8060959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:10:04+00:00 2026-06-05T10:10:04+00:00

I there a way to do nested evaluation of $-Strings in Groovy like, e.g.

  • 0

I there a way to do nested evaluation of “$-Strings” in Groovy like, e.g.

def obj = {["name":"Whatever", "street":"ABC-Street", "zip":"22222"]}
def fieldNames = ["name", "street", "zip"]

fieldNames.each{ fieldname ->
  def result = " ${{->"obj.${fieldname}"}}"  //can't figure out how this should look like
  println("Gimme the value "+result);
}

Result should be:

Gimme the value Whatever
Gimme the value ABC-Street
Gimme the value 22222

My attempts to solve this either don’t give proper results (e.g. just obj.street} or won’t compile at all.
I simply haven’t understood the whole concept so far it seems. However, seeing this: http://groovy.codehaus.org/Strings+and+GString I believe it should be possible.

  • 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-05T10:10:07+00:00Added an answer on June 5, 2026 at 10:10 am

    What about that page makes you think it’d be possible? There aren’t any nested examples.

    AFAIK it’s not possible by default; expressions within ${} aren’t re-evaluated. Which would be dangerous anyway since it’d be really easy to make it infinitely-deep and blow the stack.

    In this case, it’s not necessary anyway.

    • Make obj be an actual map, not a closure, and
    • Use normal map [] access on the field name
    def obj = [ "name": "Whatever", "street": "ABC-Street", "zip": "22222" ]
    def fieldNames = ["name", "street", "zip"]
    
    fieldNames.each { println "Gimme the value ${obj[it]}" }
    
    Gimme the value  -> Whatever
    Gimme the value  -> ABC-Street
    Gimme the value  -> 22222
    

    Edit It’s possible I misunderstood and you’re deliberately making obj a closure instead of a map, although I don’t understand why.

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

Sidebar

Related Questions

Is there any way to crate nested union types in F#? Something like this
is there way how to get name ov event from Lambda expression like with
Is there a way to find the deepest nested path with python? Like say
Is there a way to have nested controllers or at least to looks like
Is there a way to use Array_unique function working for nested array like below?
Is there a way to search for multiple nested if statements in code using
Is there a way to change the opacity of a nested element during a
Is there a way to limit the instantiation of the nested class in C#?
Is there any way to prevent NPE when accessing a nested bean using commons-beanutils?
Is there a way in symfony to get from a doctrine nested set the

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.