If we need to overwrite existing field values in one of our immutable objects, we use the data class’s “copy” function to set a new value for the desired field while preserving the rest of the values. First an example of Swift struct: struct Person ") // Person2 age: 30ĭata class is indeed displaying the expected result! We use data class to create immutable objects. On the other hand, struct is a value type. Both struct and data class are simplified versions of a class. It works fine but it is not a perfect solution. Until recently I have used data class in Kotlin whenever I need to convert a Swift struct into a Kotlin equivalent in Android project. What is the best possible equivalent of Swift Struct in Kotlin?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |