Lets say we have the famous Joshua Bloch Nutrition Builder and we want to change it so it be a bit like dynamic builder which restricts visibility of setters and propably uses generics : 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;}}Now I would like this builder to build two types of NutritionFacts. So lets say instead of:NutritionFacts cocaCola = new NutritionFacts.Builder(240, 8).  calories(100).sodium(35).carbohydrate(27).build();I would like to have something like that:NutritionFactsA a = new NutritionFacts.Builder<NutritionFactsA>...(240, 8).  calories(100).build(); //.sodium(35).carbohydrate(27) - these are not possible to be set, when I write NutritionFactsA I cannot see these parametersNutritionFactsB b = new NutritionFacts.Builder<NutritionFactsB>(240, 8).  .sodium(35).build(); //here I have set only sodium value, I cannot set anything else - I dont even see other setters...I don't know if I express myself clear and if I wrote generics in proper places... Pleas advice, show some details, I am only beginning with generics and love it!
Intelligent builder pattern - different parameters depending on type - generics?
java;design patterns;builder pattern