Java 更優雅地寫出 switch conditions
例子
在追求簡潔的路上, 大量複雜的判斷可能會採用 switch 的方式判斷, 而為了限制狀態, 可能會搭配 enums 配合, 讓 switch conditions 更容易理解與維護.
enum Player {
// 戰士
WARRIOR,
// 弓箭手
ARCHER,
// 法師
WIZARD,
}
String swordAttack() {
return "劍術攻擊";
}
String shootAttack() {
return "射箭攻擊...
jerry80409.hashnode.dev2 min read