chirag
06/20/2018, 1:27 PMdata class User(
val name: String? = null,
val address: String? = null,
val phone: String? = null
)
Suppose I have a data class like above
I am validating properties name, address, phone as not null
So if its not null how can i change its type to NotNullable because if i use this data class in anywhere else i always have to use !! or ? despite of its already validated for null check.
so that data class after validation looks like
data class User(
val name: String,
val address: String,
val phone: String
)
Anybody faced this problem ?Nicolas Chaduc
06/20/2018, 1:31 PMdata class User(
val name: String = "",
val address: String = "",
val phone: String = ""
)
ylemoigne
06/20/2018, 1:58 PMdata class RawUser(val name:String?, ...){
fun validate():User {
....
}
}
data class User(val name:String, ....)
Yes there is a lot of couling between the 2 class. But the other side of the tradeoff is that you encode model entity lifecycle into the type system, so the compiler help you to avoid error and as dev, at any place in system code, you have garantee about the lifecycle state of the entity.chirag
06/20/2018, 6:16 PMylemoigne
06/20/2018, 9:59 PMgildor
06/21/2018, 5:18 AM!!