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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:51:44+00:00 2026-05-16T05:51:44+00:00

I am reading Effective Java by Joshua Bloch. At the top of page 16,

  • 0

I am reading Effective Java by Joshua Bloch. At the top of page 16, he says:

Note that our NutritionFacts.Builder class could be declared to implement
Builder<NutritionFacts>.

But how can a “Builder” implement a “Builder” interface because there is a namespace collision there, e.g.:

public static class Builder implements Builder<NutritionFacts>...

Should I rename the inner static class to something like NutritionFacts.NutritionBuilder or what?

Here is the builder pattern he provided:

// Builder Pattern
public class NutritionFacts {
 private final int servingSize;
 private final int servings;
 private final int calories;
 private final int fat;
 private final int sodium;
 private final int carbohydrate;

public static class Builder {
    // Required parameters
    private final int servingSize;
    private final int servings;

    // Optional parameters - initialized to default values
    private int calories      = 0;
    private int fat           = 0;
    private int carbohydrate  = 0;
    private int sodium        = 0;

    public Builder(int servingSize, int servings) {
        this.servingSize = servingSize;
        this.servings    = servings;
    }

    public Builder calories(int val)
        { calories = val;      return this; }
    public Builder fat(int val)
        { fat = val;           return this; }
    public Builder carbohydrate(int val)
        { carbohydrate = val;  return this; }
    public Builder sodium(int val)
        { sodium = val;        return this; }

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

private NutritionFacts(Builder builder) {
    servingSize  = builder.servingSize;
    servings     = builder.servings;
    calories     = builder.calories;
    fat          = builder.fat;
    sodium       = builder.sodium;
    carbohydrate = builder.carbohydrate;
}
}
  • 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-16T05:51:45+00:00Added an answer on May 16, 2026 at 5:51 am

    You could fully qualify the interface name.

    i.e:

    public static class Builder implements my.package.Builder<NutritionFacts> {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading Joshua Bloch's Effective Java Programming Language Guide . He explains static
I have been reading Effective Java by Joshua Bloch and so far it really
I am reading about clone from Effective Java It says that in clone the
I have started reading Joshua Bloch's Effective Java (second edition). While reading item 2
I'm reading Effective Java Second Edition by Joshua Bloch and im confused by below
I'm reading through Chapter 3 of Joshua Bloch's Effective Java . In Item 8:
I'm reading the Effective Java book by Joshua Bloch. In the first chapter, he
I remember reading a section, possibly in Bloch's Effective Java , that said that
I'm currently reading Effective Java by Joshua Bloch and Item 17 is 'Design and
I am reading Effective Java by Joshua Bloch, item 39 make defensive copy, and

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.