后端返回可为空的Int?
date class Foo (var value: Int?){
constructor(source: Parcel) : this(
source.readInt()
)
override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeInt(value) // doesn't compile - writeInt expect no null value
}
}
现在我有办法了:
dest.writeInt(value?: -1)
然后 Select -1
or write Int like string and then use value of...
但我认为这是丑陋和错误的.
RESOLVED! My answer:
source.readValue(Int::class.java.classLoader) as Int?,
dest.writeValue(value)