Backend returns nullable Int? How should I write nullable value?
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
}
}
Now I got solution:
dest.writeInt(value?: -1)
And then check to -1
or write Int like string and then use value of...
but I think it's ugly and wrong.
RESOLVED! My answer:
source.readValue(Int::class.java.classLoader) as Int?,
dest.writeValue(value)
dest.writeInt(value!!)
work? As far as I remember Android doesn't care if you pass anull
value into Parcel. – EdorawriteInt
takes an unboxed Java integer which is not nullable. You can't pass null to this method. – Midshipmite