Kotlin には boolean と int を変換する組み込みの方法はありませんか? よくあることですが、
true -> 1
false -> 0
そうでない場合、慣用的な方法は何ですか?
ベストアンサー1
ブール値の拡張関数は次のように記述できます。
fun Boolean.toInt() = if (this) 1 else 0
Kotlin には boolean と int を変換する組み込みの方法はありませんか? よくあることですが、
true -> 1
false -> 0
そうでない場合、慣用的な方法は何ですか?
ブール値の拡張関数は次のように記述できます。
fun Boolean.toInt() = if (this) 1 else 0