![]() Use type inference judiciously declare explicit types for clarity and safety (to make sure you and the compiler are on the same page). In Kotlin, it appears the idiom is to use the built-in factory methods like mapOf and arrayOf when possible.ģ. Declarations should use generic types, like List and Map. Even with Java code, you shouldn't be declaring any variables as ArrayList or HashMap. As Stephan has already mentioned, avoid using specific implementations like HashMap and ArrayList. It seems to you have previously programmed in Java and have carried over some poor habits from working in Java.Ģ. 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. ![]() 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.
0 Comments
Leave a Reply. |