Since the latest update Android Studio gives me following warning:
Expected type does not accept nulls in Kotlin, but the value may be null in Java
This warning shows up at following code snipped:
data class Person(
@SerializedName("surname")
surname : String
) {
constructor(parcel: Parcel) : this(
parcel.readString()
)
//Parceable implementation
}
There are to way to fix it, and hide this warning:
First is to make value type nullable, which means changing String to String?.
Second is to make readString always return non-null value - readString()!!
My question is which approach is better. Is it possible that readString will return null, if the value can't be nullable?