kotlin 实现类Parcelize的问题

@Parcelize
class Book(val title: String, val author: String, val year: Int) : Parcelable

并且在app的build.gradle中添加

androidExtensions {
    experimental = true
}

这时还会报错

编译器会警告This class implements Parcelable but does not provide a CREATOR field@SuppressLint("ParcelCreator")注释解决了这个问题

所以,还需要在类中添加注解

@Parcelize
@SuppressLint("ParcelCreator")
class Book(val title: String, val author: String, val year: Int) : Parcelable

你可能感兴趣的:(kotlin,CREATEOR,Parcelable)