【发布时间】:2021-12-07 19:46:42
【问题描述】:
我对 kotlin 中的集合感到困惑。
结构有点复杂。
data class Request(
val region: Region,
val promotions: List<Promotion>,
)
data class Promotion(
var promotionCode: String,
val promotionType: String,
val coupons: List<Coupon>
)
data class Coupon(
val reminderType: ReminderType,
val couponCode: String,
val count: Int,
val couponMultiLanguages: List<CouponDescription>
)
现在我想得到一张地图,Map<ReminderType, List<Promotion>>,其中键 ReminderType 是优惠券级别中的 val,值 List<Promotion> 是促销列表,由优惠券中的每个 ReminderType 值过滤
我卡在这里
val result: Map<ReminderType, List<Promotion>> = promotions.map { it.coupons.groupBy { it.reminderType } }
【问题讨论】:
-
G2Coupon类与Coupon类不同吗? -
@sidgate 对不起,它是一样的。已经修好了
标签: java dictionary kotlin group-by collections