【发布时间】:2020-05-18 18:30:30
【问题描述】:
这里的Customer 和BodyModel 是数据类。我需要User、toCustomer() 的内部函数,将User class 转换为Customer class。我坚持将Boolean type 更改为Customer.Type
客户类别
data class Customer(
val id: String,
val bodyModel: BodyModel?,
val isDrinks : Type
){
enum class Type(val type: String, val value: Boolean) {
NO("No", false),
YES("Yes", true)
}
}
BodyModel 类
data class BodyModel(
val height: Int?,
val weight: Int?
)
用户类
data class User(
val id: String,
val height: Int?,
val isDrinks: Boolean?
){
@Ignore
fun toCustomer() = Customer(
id,
BodyModel(height?:-1, -1 ),
Customer.Type(?????????)
)
【问题讨论】:
-
Customer.Type.NO或Customer.Type.YES。但是为什么要使用枚举来表示本质上是布尔值呢? -
@Tenfour04,我的服务器将
isDrinks作为Boolean提供。我在具有枚举逻辑的 radioGroup 的 UI 中实现了这一点。我需要将isDrinks传递给Customer.Type.YES or Customer.Type.NO