If I have a data class thats mostly nullables, is ...
# announcements
g
If I have a data class thats mostly nullables, is there anyway to quickly cast all of them to non null? or is it just a matter of having to do the null checks manually?
m
Copy code
data class Nullables(val first: String?, val second: Any?) {
    fun nonNull() = NonNull(first!!, second!!)
}
data class NonNull(val first: String, cal second: Any)
g
Needs to be a safe way to do it I guess, hmm
m
Copy code
fun nonNullOrNull(): NonNull? {
    val fst = first ?: return null
    val snd = second ?: return null
    return NonNull(fst, snd)
}