Again, making Product immutable will require a shift in the way you're thinking about your program objects. You might also be able to keep your Product data class immutable as well:ĭata class Product(val name: String, val availableQuantity: Int)Īlthough I'd have to see more details of how you're using it. This leads to non-functional code: var data: Map> That being said, I think I have a pretty decent handle on some of the Kotlin idioms. Convenience: The listOf() function is a simple and convenient way to create lists of elements in Kotlin.If you don't mind, a few comments on style.Ĭaveat: I've just recently started out with Kotlin myself so there may be better and more idiomatic ways than what I'm about to suggest below.This can help prevent errors caused by passing the wrong type of data to a function or method.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |