美文网首页
[Kotlin] Kotlin实现Parcelable

[Kotlin] Kotlin实现Parcelable

作者: 整整代码 | 来源:发表于2020-05-03 14:27 被阅读0次

实现方式有二种:

一、使用注解

1.在gradle中添加

android {
    ...
    //使用Kotlin实验特性    
    androidExtensions {
        experimental = true
    }
}
  1. 使用注解标记数据类并实现Parcelable接口
@SuppressLint("ParcelCreator")
@Parcelize
data class User(val name: String, val age: Int) : Parcelable

二、使用 Android Studio 插件快速生成

搜索Parcelable Code Generator(for kotlin)插件安装

相关文章

网友评论

      本文标题:[Kotlin] Kotlin实现Parcelable

      本文链接:https://www.haomeiwen.com/subject/qcmdghtx.html