mercredi 24 juin 2020

Kotlin check if data class properties are all null

Suppose I have a data class with nullable properties:

data class User(
   val fName: String?,
   val lName: String?)

In a function where I receive an instance of such a class even if the instance is not null I want to check that at least one of the properties inside is initialized and not null. I know that I can check the properties one by one, but I want to have something more generic, I googled and seems Kotlin there is no extension function for this so I implemented one and would like to share with you and check if anyone knows better ways.





Aucun commentaire:

Enregistrer un commentaire