Simple Kotlin Tips for Beginners

Share

When beginning to learn a new programming language, it’s important to have an overview of the fundamentals. That said, here are some useful tricks that will help ease you into learning Kotlin if you’re just starting out.

Apply

A common use case for apply is to make additional configurations on a recently created object:

currentTheme?.let{applyTheme(theme)// we are certain it is not null heresendAnalyticsThemeEvent(theme)}

Finally, there is !!, which converts any value to a non-null type and throws an exception if the value is null. This operator may look like an easy escape for null handling chores, but it should be avoided at all costs since Kotlin does so much to help to get rid of NPEs.

There is much more to Kotlin, but for the sake of simplicity, this is a good starting point. Hopefully, it will be a useful guide about frequently used Kotlin practices to help get you up and running.