Skip to content

Instantly share code, notes, and snippets.

@gyugyu90
Last active October 12, 2024 05:40
Show Gist options
  • Save gyugyu90/385fcfcceea925fbaf9504e4d0e935ae to your computer and use it in GitHub Desktop.
Save gyugyu90/385fcfcceea925fbaf9504e4d0e935ae to your computer and use it in GitHub Desktop.
class Tea {
final String teaBag;
Milk? milk;
Tea(this.teaBag, [this.milk]);
String getFullName() {
if (milk != null) {
return "$teaBag 밀크티";
}
return "$teaBag 티";
}
}
class Milk {
String name = "서울우유";
int amount = 100;
}
void main() {
var tea = Tea('얼그레이');
print(tea.getFullName()); // 얼그레이 티
// tea.teaBag = "캐모마일"; // Error: The setter 'teaBag' isn't defined for the class 'Tea'.
tea.milk = Milk();
print(tea.getFullName()); // 얼그레이 밀크티
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment