![]() ![]() ![]() You can use the copy() function to copy an existing object into a new object and modify some of the properties while keeping the existing object unchanged. Kotlin Cast Any to List or Map: Unchecked Cast. Kotlin makes working with immutable data objects easier by automatically generating a copy() function for all the data classes. ![]() Since they can not be modified after creation, you donât need to worry about concurrency issues that arise when multiple threads try to modify an object at the same time. Immutable objects are easier to work with and reason about while working with multi-threaded applications. Letâs understand what these functions do and how to use them - Data Classes and Immutability: The copy() functionĪlthough the properties of a data class can be mutable (declared using var), Itâs strongly recommended to use immutable properties (declared using val) so as to keep the instances of the data class immutable. Public class Customer " ) // Prints -1841845792Īpart from the standard methods like equals(), hashCode() and toString(), Kotlin also generates a copy() function and componentN() functions for all the data classes. any - Kotlin Programming Language Common JVM JS Native Version 1.8 kotlin-stdlib / llections / any any Common JVM JS Native 1.0 fun Array.any(): Boolean (source) fun ByteArray.any(): Boolean (source) fun ShortArray.any(): Boolean (source) fun IntArray.any(): Boolean (source) fun LongArray.![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |