【发布时间】:2022-07-06 02:49:45
【问题描述】:
我正在尝试将 Parcelable 模型从 Java 迁移到 Kotlin。
我的模型如下所示:
import kotlinx.parcelize.*
@Parcelize
class SignatureAuthorityModel
(var id: Int,
var cloudId: Int,
var uuid: UUID?): android.os.Parcelable
{
override fun equals(other: Any?): Boolean
{
//equals implementation
}
override fun hashCode(): Int
{
//some hash implementation
}
override fun toString(): String
{
//some stringifier implementation
}
}
我可以为此模型调用 writeToParcel,但 SignatureAuthorityModel.createFromParcel(parcel) 不可用。我必须单独编写它,还是必须以某种方式配置 kotlin-parcelize 插件?从 kotlin 文档来看,当我使用 @Parcelize 注释时,似乎也应该自动生成 createFromParcel ,并且只有当我有一些高级逻辑时,我才必须在伴随对象 Creator 中编写实现.正确的做法是什么?
【问题讨论】: