kotlin - 为什么在 kotlin 中不支持暂停 operator fun getValue?
问题描述
为什么以下签名会产生Unsupported [suspend operator "getValue"]
编译错误?
suspend operator fun getValue(thisRef: Any?, property: KProperty<*>): T
是因为技术限制吗?
解决方案
getValue
操作符用于实现 a 的 getter,没有val
a 之类的东西suspend val
——只有一个普通的val
。
Asuspend fun
不能直接从普通函数中调用,例如 getter 的实现——因此它getValue
不能用于其预期目的。Kotlin 通过在尝试创建suspend operator fun getValue
.
推荐阅读
- django - Django注销未注销用户
- javascript - 将类转换为钩子,获取属性 'then' 在类型 '(dispatch: any) => Promise 上不存在
' - django - 有没有其他方法可以使用上传部分从前端上传图片?不显示并从 index.html 页面上传
- python - 如何解耦graphql/graphene突变
- csv - 在 Rust 中使用带有 serde 的嵌套枚举/结构序列化/反序列化 CSV
- git - 推送时出现 Github 错误:未知速记标志:-t 中的 't'
- deployment - 如何配置 Helm 以使用 AKS 将多个微服务(支付、订单)部署到不同的环境(开发、QA)中?
- python - 如何在离线绘图上自定义或禁用右键菜单?
- css - 从橙色到蓝绿色的动画没有生效
- sql - 数据库关联导致使用 postgres 进行数据库迁移时出现问题