Skip to content

Instantly share code, notes, and snippets.

@rinotc
Created August 1, 2021 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rinotc/af68b16fb64fd9312be24e3c728a5ff8 to your computer and use it in GitHub Desktop.
Save rinotc/af68b16fb64fd9312be24e3c728a5ff8 to your computer and use it in GitHub Desktop.
テレスコーピング・コンストラクタのサンプル
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 NutritionFacts(int servingSize, int servings) {
this(servingSize, servings, 0);
}
public NutritionFacts(int servingSize, int servings, int calories) {
this(servingSize, servings, calories, 0);
}
public NutritionFacts(int servingSize, int servings, int calories, int fat) {
this(servingSize, servings, calories, fat, 0);
}
public NutritionFacts(int servingSize, int servings, int calories, int fat, int sodium) {
this(servingSize, servings, calories, fat, sodium, 0);
}
public NutritionFacts(int servingSize, int servings, int calories, int fat, int sodium, int carbohydrate) {
this.servingSize = servingSize;
this.servings = servings;
this.calories = calories;
this.fat = fat;
this.sodium = sodium;
this.carbohydrate = carbohydrate;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment