Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
テレスコーピング・コンストラクタのサンプル
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