Implementing Builder interface in Effective Java book
<p>I am reading Effective Java by Joshua Bloch. At the top of page 16, he says:</p>

<pre><code>Note that our NutritionFacts.Builder class could be declared to implement
Builder&lt;NutritionFacts&gt;.
</code></pre>

<p>But how can a "Builder" implement a "Builder" interface because there is a namespace collision there, e.g.:</p>

<pre><code>public static class Builder implements Builder&lt;NutritionFacts&gt;...
</code></pre>

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

<p>Here is the builder pattern he provided:</p>

<pre><code>// 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;
}
}
</code></pre>
