val customerIdent = custIdentByCustomerId(id).firstOption
customerIdent.getOrElse (None)
我不想返回None,想要返回类型为CustomerIdentification
的空customerIdent。
如果我这样做:
customerIdent.getOrElse (None)
编译器说:
[error] C:\Code\...\scala\models\Customer.scala:125: type mismatch;
[error] found : None.type [error] required: models.CustomerIdentification
[error] customer.get.status, customer. get.rec_marketing_messages, customerIdent.getOrElse (None))
请帮忙
答案 0 :(得分:0)
您是否能够构建CustomerIdentification的空版本?类似的东西:
val emptyIdent = CustomerIdentification()
然后你可以说:
val customerIdent = custIdentByCustomerId(id).firstOption
customerIdent.getOrElse(emptyIdent)