O'Reilly logo

Android Development with Kotlin by Igor Wojda, Marcin Moskala

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extension functions

All bigger Java projects have utility classes, such as StringUtils, ListUtils, AndroidUtils, and so on. It is so popular because util functions capture common patterns and allow them to be tested and used in a simpler way. The problem was that Java really poorly supports the creation and usage of such functions, because they have to be implemented as static functions of some class. Let's discuss this problem with an example. Every Java Android developer knows well the following code used to show Toast:

    Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); 

It is commonly used in Android projects for showing errors or short messages, and often it is presented at the beginning of most Android tutorials. Code that implements ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required