Kotlin

How lambdas work in Kotlin. setOnClickListener transformation (KAD 18)

Although I spoke a little about it in another article, I’d like to explain in depth how lambdas work in Kotlin, and how they transform the interfaces with a single method in lambdas when we  are working with Java libraries. In particular I’m going to show you some examples on how to simplify the use of …

How lambdas work in Kotlin. setOnClickListener transformation (KAD 18) Read More »

Operator Overload in Kotlin: Add standard operations to any class (KAD 17)

In Kotlin, as in every language, we have predefined operators to perform certain operations. The most typical are the addition (+), subtraction (-), multiplication (*) or division (/), but there are a few more. In some languages, such as Java, these operators are limited to certain types of data, and we have no way to …

Operator Overload in Kotlin: Add standard operations to any class (KAD 17) Read More »

Property delegation in Kotlin: Assign values in Android without having the context (KAD 15)

As we’ve seen in previous articles, properties need a default value, they can’t be declared without assigning them a value. This is a problem, because imagine that you want to store a view into a property. As this code is executed during object creation, you can’t access the context at that time. What can you do? If …

Property delegation in Kotlin: Assign values in Android without having the context (KAD 15) Read More »

Reified Types in Kotlin: how to use the type within a function (KAD 14)

One of the limitations that most frustrates Java developers when using generics is not being able to use the type directly. Normally this is solved by passing the class as a function parameter, making the code more complex and unattractive. In Kotlin, thanks to the inline functions, which we’ve already discussed, we can use reified types that …

Reified Types in Kotlin: how to use the type within a function (KAD 14) Read More »

Using “when” expression in Kotlin: The “switch” with super powers (KAD 13)

The switch expression in Java, and especially in Java 6, are extremely limited. Apart from a very short amount of types, it can not be used for anything else. But, however, when expressions in Kotlin can do everything you can do with a switch and much more. Actually, with when you can substitute the most complex if/else you can have in your …

Using “when” expression in Kotlin: The “switch” with super powers (KAD 13) Read More »

Take Realm to the next level with Kotlin

When someone asks me what I like the most about Kotlin, I find it hard to highlight a single feature. Data classes, lambdas, type inference, delegates, coroutines… all of which entail a complete series of significative improvements which makes the difference with respect to Java on a daily basis. Discovering Kotlin extensions Definitely, one of …

Take Realm to the next level with Kotlin Read More »

Ninja Functions in Kotlin. Understanding the power of generics (KAD 12)

The combined use of several Kotlin features mixed with the use of generics allow to create functions that will greatly simplify your code, while maintaining its readability. There are several functions included in the Kotlin library that are really useful, and once you have mastered some concepts they will be also very easy to use. If you want to learn …

Ninja Functions in Kotlin. Understanding the power of generics (KAD 12) Read More »

Data classes in Kotlin

Data Classes in Kotlin: save a good bunch of lines of code (KAD 10)

We’ve already seen the classes in an earlier article, but data classes go a little further in helping us simplify our code. What are data classes? A data class is a class that only contains state and does not perform any operation. The advantage of using data classes instead of regular classes is that Kotlin gives …

Data Classes in Kotlin: save a good bunch of lines of code (KAD 10) Read More »