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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:16:44+00:00 2026-06-03T08:16:44+00:00

I’m trying out Effective Java book and enjoying it. I read Builder pattern and

  • 0

I’m trying out Effective Java book and enjoying it. I read Builder pattern and I tried to play with it. I have a code like this (in Groovy):

public class Anto {
    public static void main(String[] args) {

            def testing = new Java.Builder(1).author("antoaravinth").build()
            println testing.author
        }
}

class Java {
    int version
    def author
    int release_number

    public static class Builder {
        int version

        def author = ""
        int release_number = 0

        public Builder(int version) {
            this.version = version
        }

        public Builder version(int version)
        {
            version = version
            return this
        }

        public Builder author(def author)
        {
            author = author
            return this
        }

        public Builder release_number(int release_number)
        {
            release_number = release_number
            return this
        }

        public Java build() {
            return new Java(this);
        }


        private Java(Builder builder) 
        {
            version = builder.version
            author = builder.author
            release_number = builder.release_number
        }

    }
}

But I get error like this :

Caught: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: Java(Java$Builder)
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: Java(Java$Builder)
    at Java$Builder.build(Anto.groovy:43)
    at Java$Builder$build.call(Unknown Source)
    at Anto.main(Anto.groovy:4)

I don’t know why this happens! Where I went wrong?

  • 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-03T08:16:46+00:00Added an answer on June 3, 2026 at 8:16 am

    This is your build() method:

    public Java build() {
        return new Java(this);
    }
    

    Look at your Java class (not the Builder) – it doesn’t have any explicitly-declared constructors, so the only constructor it has is the public parameterless one declared automatically for you.

    You need to move this:

    private Java(Builder builder) 
    {
        version = builder.version
        author = builder.author
        release_number = builder.release_number
    }
    

    outside the Builder class. (I’m slightly surprised Groovy didn’t complain earlier, but I’m pretty sure that’s the problem…)

    EDIT: Now that it’s not throwing an exception, look at your “setter” methods:

    public Builder version(int version)
    {
        version = version
        return this
    }
    

    The version = version line doesn’t do anything. You need to differentiate between the parameter and the field, e.g.

    public Builder version(int version)
    {
        this.version = version
        return this
    }
    

    … or by giving the parameter a different name, e.g.

    public Builder version(int value)
    {
        version = value
        return this
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

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.