Kotlin tips
Kotlin Tips is a series of short videos where members of the Kotlin team show how to use Kotlin in a more efficient and idiomatic way to have more fun when writing code.
Subscribe to our YouTube channel to not miss new Kotlin Tips videos.
Return and throw with the Elvis operator
Elvis has entered the building once more! Seb explains why the operator is named after the famous singer, and how you can use ?:
in Kotlin to return or throw. The magic behind the scenes? The Nothing type.
Destructuring declarations
With destructuring declarations in Kotlin, you can create multiple variables from a single object, all at once. In this video Sebastian shows you a selection of things that can be destructured – pairs, lists, maps, and more. And what about your own objects? Kotlin’s component functions provide an answer for those as well:
Operator functions with nullable values
In Kotlin, you can override operators like addition and subtraction for your classes and supply your own logic. But what if you want to allow null values, both on their left and right sides? In this video, Sebastian answers this question:
Timing code
Watch Seb give a quick overview of the measureTimedValue()
function, and learn how you can time your code:
Improving loops
In this video, Sebastian will demonstrate how to improve loops to make your code more readable, understandable, and concise:
Strings
In this episode, Kate Petrova shows three tips to help you work with Strings in Kotlin:
Doing more with the Elvis operator
In this video, Sebastian will show how to add more logic to the Elvis operator, such as logging to the right part of the operator:
Kotlin collections
In this episode, Kate Petrova shows three tips to help you work with Kotlin Collections:
What’s next?
See the complete list of Kotlin Tips in our YouTube playlist
Learn how to write idiomatic Kotlin code for popular cases