0
我在看下面的HAXE源代碼從「模式匹配 - 矩陣匹配」在try.haxe.org例子 -使用抽象爲枚舉類型?
class Test {
static function main() {
var playerA = {
name: "Simn",
move: Move.Paper
}
var playerB = {
name: "Nicolas",
move: Move.Rock
}
// a switch can directly return something
var winner = switch ([playerA.move, playerB.move]) {
case [Move.Rock, Move.Paper]: playerB;
case [Move.Scissors, Move.Paper]: playerA;
default: null;
}
if (winner != null) {
trace('The winner is: ${winner.name}');
} else {
trace('Draw!');
}
}
}
@:enum
abstract Move(Int) {
var Rock = 1;
var Paper = 2;
var Scissors = 3;
}
我的問題是:
- 是什麼符號
@:enum
意味着什麼? 他們爲什麼要創建枚舉類型這樣,而不是簡單地做:
枚舉移動 { 岩石; 紙; 剪刀; }