【发布时间】:2015-04-26 01:03:23
【问题描述】:
Kotlin 是否有类似区分联合(求和类型)的东西?这个(F#)的惯用 Kotlin 翻译是什么:
type OrderMessage =
| New of Id: int * Quantity: int
| Cancel of Id: int
let handleMessage msg =
match msg with
| New(id, qty) -> handleNew id qty
| Cancel(id) -> handleCxl id
【问题讨论】:
标签: kotlin algebraic-data-types discriminated-union