AIDL 中的 Parcelize 注释:不兼容的类型:对象无法转换为 MyCustomObject

Parcelize annotation in AIDL: Incompatible types: Object cannot be converted to MyCustomObject

我正在将我的模型 class 重写为 Kotlin,它必须是 Parcelable 并用于 AIDL:

@Parcelize
data class MyCustomObject(val value1: String, val value2: String) : Parcelable

在编译期间崩溃并出现错误:

error: incompatible types: Object cannot be converted to MyCustomObject

并指向生成代码中的这一行:

if ((0!=_reply.readInt())) {
    _result = com.mypackagename.MyCustomObject.CREATOR.createFromParcel(_reply);
}

我将这个注解用于其他目的,没问题,到目前为止我只在 AIDL 中发现不匹配。

有什么问题吗?

编辑:5 天后我没有发表任何评论 a ticket for this issue

这是 Kotlin 中的一个错误,所以我将这个问题重定向到 JetBrains。 你可以在这里跟踪它:KT-25807.

发生这种情况,因为 createFromParcel() 不是 return class T,而是 Object.

UPD

Parcelize 注释现在可由 Google 维护,该问题已在 kotlin 1.5.+ 版本中得到修复 https://issuetracker.google.com/issues/110131003