Familiar with using the Kotlin Playground for creating and editing Kotlin programs. In this codelab, you will use the Kotlin Playground to become familiar with lists in Kotlin and create a program for ordering different variations of noodle soup. Learning how to create and use lists is an important programming concept to add to your toolbox, and it will enable you to create more sophisticated apps. For example, there could be a list of news articles, songs, calendar events, or social media posts within an app. In programming, lists are also very useful. This is why it is called declaration-site variance.It's common to make lists for all sorts of situations in your everyday life such as a list of things to do, a list of guests for an event, a wish list, or a grocery list. In Kotlin, the developer that writes the class declaration needs to consider the variance and not the developer who uses the code. This means that all methods in Compare can have T as an argument but cannot return T type. In this case, there is in keyword next to the parameter. Whenever we compare dogs we look how cute the dogs are, here is code for comparing dogs: val dogCompare: Compare = object: Compare Perhaps we want to compare our animals, that’s why we can create an interface Compare, with a method compare(T item1, T item2) and that method can say which item is first and which item is second.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |