I want to add to the list objects only if they have all fields, and try this code:
data class Response(val id: String, val name: String)
val list = mutableListOf<Response>()
val id : String? = "test_id"
val name : String? = "test_name"
if (!id.isNullOrBlank() and !name.isNullOrBlank()) {
list.add(Response(id, name)) // Type mismatch. Required String, Found String?
}
But I got an error: Type mismatch. Required String, Found String?
What is the correct (and compact) way to do it?