farzad
11/24/2019, 8:23 AMdata class RequestModel(
val description: String?
)
and a validation function
fun validate(model: RequestModel): RequestModel{
if(model.description == null) throw IllegalArgumentException("description must be non null")
return model
}
After this validation step, I need a way to indicate non-nullability of description
property.
One solution is to create a new data class which has non null propertis data class RequestModel(val description: String)
.
But I'm looking for a generic way to avoid creating new classes per use case.
Ideal generic solution:
fun validate(model: RequestModel): NoNullableField<RequestModel>
How can I remove nullability from properties of a c.lass with nullable properties in a generic way? Is it usefull to use some kind of kotlin compiler contract?
Link to SO question: https://stackoverflow.com/questions/59015821Alowaniak
11/24/2019, 12:36 PMfarzad
02/23/2020, 9:13 AM