You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kotlin中MutableState<List<String>>调用contains出现类型不匹配问题

解决MutableState<List>调用contains时的类型不匹配错误

你遇到的问题根源在于selectedOptions是MutableState<List<String>>类型——它是Jetpack Compose的状态容器,并非直接的List实例。直接调用contains()方法会因为接收者类型不匹配触发错误。

修正方法很简单,访问MutableState的value属性获取内部的List对象,再调用contains():

错误代码:

checkComp = selectedOptions.contains("Compliance Fee")

修正后:

checkComp = selectedOptions.value.contains("Compliance Fee")

在Composable函数中,selectedOptions.value会自动绑定重组机制,当状态内的List更新时,代码会自动重新计算checkComp的值,完全符合Compose的状态管理逻辑。

内容的提问来源于stack exchange,提问作者The Quackiest

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 03:10:55