[关闭]
@cxm-2016 2016-08-16T08:58:46.000000Z 字数 525 阅读 1902

Android中Parcelable接口的Koltin实现方式

android no


  1. data class UserBean(
  2. var name: String,
  3. var age: Int
  4. ) : Parcelable {
  5. constructor(source: Parcel) : this(source.readString(), source.readInt())
  6. override fun describeContents() = 0
  7. override fun writeToParcel(dest: Parcel?, flags: Int) {
  8. dest?.writeString(name)
  9. dest?.writeInt(age)
  10. }
  11. companion object {
  12. @JvmField val CREATOR: Parcelable.Creator<UserBean> = object : Parcelable.Creator<UserBean> {
  13. override fun createFromParcel(source: Parcel): UserBean = UserBean(source)
  14. override fun newArray(size: Int): Array<UserBean?> = arrayOfNulls(size)
  15. }
  16. }
  17. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注