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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:15:03+00:00 2026-06-04T08:15:03+00:00

In Groovy, when I call a map constructor, e.g. new Player(name:’Lionel’, surname:’Messi’, number: 10,

  • 0

In Groovy, when I call a map constructor, e.g.

new Player(name:'Lionel', surname:'Messi', number: 10, team:barcelona)

how do I know the order in which property setters will be called?

I need to know this because I need to apply certain logic in some of my setters, and I need to know which data will be set in the object when each setter is called.

  • 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-04T08:15:04+00:00Added an answer on June 4, 2026 at 8:15 am

    With a quick script, it seems that they are set in the order that are passed:

    class Foo {
        def settersCalled = []
        def setFoo(foo) { settersCalled << 'foo' }
        def setBar(bar) { settersCalled << 'bar' }
        def setBaz(baz) { settersCalled << 'baz' }
    }
    
    assert new Foo(foo: 0, bar: 0, baz: 0).settersCalled == ['foo', 'bar', 'baz']
    assert new Foo(bar: 0, foo: 0, baz: 0).settersCalled == ['bar', 'foo', 'baz']
    assert new Foo(baz: 0, bar: 0, foo: 0).settersCalled == ['baz', 'bar', 'foo']
    

    However, you can understand more about what Groovy is doing by following the code with a debugger. If you put a breakpoint in one of the setters in that code, you’ll notice that the call-stack includes MetaClassImpl.setProperties, which means that these properties are being set by that method. If we take a look at setProperties‘ code we can confirm that it is using the map iterator to traverse the map that is passed in the constructor. And, as Groovy uses LinkedHashMaps, which are ordered, as the default Map implementation, we can conclude that those properties will be set in the order that they are defined in the constructor’s map 🙂

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

Sidebar

Related Questions

I call some cloud that allows to execute groovy scripts. I return data as
I am attempting to call the Apache Commons StringUtils.join() method from within a Groovy
In Groovy, how do I extract a new list from the following: def people
I am executing groovy script in java: final GroovyClassLoader classLoader = new GroovyClassLoader(); Class
I need to call a number of methods in parallel and wait for results.
I have some legacy Java code inside which I'd like to call a groovy
I am learning Groovy CliBuilder and I find it great, except, I don't know
I'm an idiot or something, and I don't know how to add groovy into
I'm new to SoapUI and Groovy, but an experienced Java programmer. I created a
In groovy, how do you dynamically call a static method of a class? void

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.