![]() 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. So, you can only use a switch to perform an action when one specific variable has a certain precise value.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. However it cannot replace all sort of if/else sequences but just those which compare a value with some constant. One of the most useful improvement, especially if you come from Java, is the when construct.Ī traditional switch is basically just a statement that can substitute a series of simple if/else that make basic checks. Kotlin is full of these pragmatic improvements, getting its user a language that just feel good to use. There are two kinds of innovation: new perspectives that changes how we look at things and pragmatic improvements that changes how we do things.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |