为什么@Parcelize注解需要实现抽象方法?

问题描述 投票:0回答:1

我正在尝试获得自动生成的 Parceable 的优势,例如此处描述的(例如:)-

https://stackoverflow.com/a/63906355/5709159

https://medium.com/@BladeCoder/a-study-of-the-parcelize-feature-from-kotlin-android-extensions-59a5adcd5909

据我所知,唯一的要求是将班级声明为

Parcelable
并用
@Parcelize
注释它,如下所示:

@Parcelize
class Person(val name: String, val age: Int) : Parcelable

但是,我收到一条错误消息:

Class 'Person' is not abstract and does not implement abstract member public abstract fun describeContents(): Int defined in android.os.Parcelable

它迫使我实施这些方法:

@Parcelize
class Person(val name: String, val age: Int) : Parcelable {
    override fun describeContents(): Int {
        TODO("Not yet implemented")
    }

    override fun writeToParcel(dest: Parcel, flags: Int) {
        TODO("Not yet implemented")
    }
}

这不是预期的,我在这里错过了什么?

android kotlin parcelable
1个回答
0
投票

这是已知错误,我认为它已经修复,但您可以查看此 youtrack 票以获取更多信息。如果它已修复,只需更新到已修复的版本,错误就会消失。

最重要的是,即使存在该错误,您的代码也应该可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.