HarmonyOS鸿蒙Next中使用Sendable特性时抛异常:Cannot set sendable property with mismatched type
HarmonyOS鸿蒙Next中使用Sendable特性时抛异常:Cannot set sendable property with mismatched type 当使用@Sendable标记为Sendable类时,就会导致运行时 crash,不用sendable,编译和运行都没问题。
感谢提问,为了更快的解决您的问题,请提供以下信息:
- 操作系统/版本
- 复现步骤
- 错误日志
- 最小复现demo
我们将在收到信息后尽快处理。
更多关于HarmonyOS鸿蒙Next中使用Sendable特性时抛异常:Cannot set sendable property with mismatched type的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
sendable会在进行属性赋值的时候进行类型强校验。可以再排查下报错文件编译产物的ts文件下对应的行数,看下具体是什么操作导致的类型校验异常。参考一下文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/sendable-constraints#arkts通用规则目前只针对sendable对象
在HarmonyOS鸿蒙Next中,Sendable
特性用于跨线程传递数据。当出现“Cannot set sendable property with mismatched type”异常时,通常是因为尝试设置Sendable
属性时,传递的数据类型与属性声明的类型不匹配。确保传递的数据类型与属性定义的类型一致即可避免此异常。