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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:04:15+00:00 2026-05-29T10:04:15+00:00

I got confused with this two lines of coding : this.class.methods.name This is called

  • 0

I got confused with this two lines of coding :

this.class.methods.name

This is called Gpath (Am I right?). Now consider this code :

count = 0
def a = [1,2,3,4,5,5,51,2]
a.findAll { it == 5 }​.each { count ++ }
println count

The line:

a.findAll { it == 5 }​.each { count ++ }

is called as a method chaining or Gpath?

Literally, I got struck with these two meanings. It will be nice if some one explains the difference between these two.

Thanks in advance.

​

  • 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-05-29T10:04:16+00:00Added an answer on May 29, 2026 at 10:04 am

    I’m not sure if I understand the question correctly.

    As I see it, in both examples you are using method chaining, simply because you are calling a method in the object that is returned by another method. But, as Arturo mentions, some people confuse method chaining and fluent interfaces. A fluent interface is indeed quite handy if you want to chain methods.

    In Groovy, however, you may, instead of coding a fluent interface yourself, use the with method in any object. For example, using the same Person and Address classes that Arturo defined, you can do:

    def person = new Person()
    person.with {
        name = 'John'
        age = 25
        address = new Address('Boulevard St')
    }
    assert person.name == 'John' &&
           person.age == 25 &&
           person.address.name == 'Boulevard St'
    

    Now, GPath, as I understand, is just a way of accessing the properties of an object. For example, if you have the class:

    class Foo {
        def bar
    }
    

    The GPath mechanism in Groovy lets you do things like:

    def foo = new Foo(bar: 42)
    assert foo.bar == 42
    

    Instead of accessing the bar property with its getter, like foo.getBar(). Nothing too fancy. But other classes in Groovy also have some GPath magic and there is where things get more interesting. For example, lists let you access properties in their elements the same way you’d access normal properties:

    def foos = (1..5).collect { new Foo(bar: it) } // Five Foos.
    assert foos.bar == [1, 2, 3, 4, 5]
    

    As you can see, accessing the bar property on a list of objects that have that property will result in a list with the values of that property for each object in the list. But if you access a property that the elements of the list don’t have, e.g. foos.baz, it will throw a MissingPropertyException.

    This is exactly what is happening in:

    this.class.methods.name
    

    I, however, consider this behavior to be a little too magic for my taste (unless you are parsing XML, in which case is totally fine). Notice that if the collection returned by the methods method would be some weird collection that had a name property, methods.name would result in that name instead of the names of each method in the collection. In these cases I prefer to use the (IMO) more explicit version:

    this.class.methods*.name
    

    Wich will give you the same result, but it’s just syntax sugar for:

    this.class.methods.collect { it.name }
    

    … and let’s the intention of the expression to be more clear (i.e. “I want the names of each method in methods“).


    Finally, and this is quite off-topic, the code:

    count = 0
    def a = [1,2,3,4,5,5,51,2]
    a.findAll { it == 5 }​.each { count ++ }
    println count
    

    can be rewritten as:

    def a = [1,2,3,4,5,5,51,2]
    def count = a.count { it == 5 }
    println count
    

    🙂

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

Sidebar

Related Questions

I was actually going through the question 1636644 .. and got confused with this
I have the following code and got myself confused: I have a query that
To keep this simple, lets say I have two tables. The first is called
I'm pretty confused on how to go about this. Say I have two columns
I got a bit confused: In production we have two processes communicating via shared
I've got confused . We hear a lot about Provider in ASP.NET . Membership-Provider
today I got confused when doing a couple of <%=Html.LabelFor(m=>m.MyProperty)%> in ASP.NET MVC 2
I'm new in Reporting services and got little confused. in the screen shot you
I'm quite confused by something. I've got 2 select lists, and if you choose
I'm pretty confused. I have a point: x= -12669114.702301 y= 5561132.6760608 That I got

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.