I just announced the new Spring 5 modules in REST With Spring:
Kotlin is a new statically-typed language in the JVM world with a developer-friendly syntax and strong Java interoperability.
It’s now also a first-class language on the Android platform.
Starting at the top – this is the high-level overview of the language, highlighting its most interesting features.
Kotlin features a new modern approach to compile-time null-safety. Here, we explore it in depth.
Kotlin has his own set of visibility modifiers – some are borrowed directly from Java, some are not.
In this one, we introduce the Kotlin’s Collections API and go through its features.
Generics are slightly more flexible than in Java. We see how to use the out and in keywords properly. We look at type projections and defining a generic method that uses generic constraints.
Even though it’s not possible to do pattern matching using when in Kotlin, as is the case with the corresponding structures in Scala and other JVM languages, the when block is versatile enough to make us totally forget about these features.
There’s also an easy way for creating plain data holders without writing any excessive boilerplate.
Sealed classes can be an invaluable tool for your API design toolbox. Allowing a well-known, structured class hierarchy that can only ever be one of an expected set of classes can help remove a whole set of potential error conditions from your code, whilst still making things easy to read and maintain.
Collections API has methods similar to those found in the Java Stream API but they do not always behave the same.
Here, we can see how to use destructuring declarations in Kotlin.
The approach to equality operators is slightly different than in Java.
If we want to mix Kotlin and Java code, we can do that easily.
We can also easily optimize tail-recursive methods.
Class properties do not always need to be backed back a field in a particular class, we can also delegate them.
Coroutines are a new, lightweight approach to concurrency.
We delve into Kotlin lazy keyword that is used for lazy initialization of properties. In the end, we see how to defer assigning variables using the lateinit keyword.
Here, we have a look at how to set up our project to use Mockito and Kotlin together, and how we can leverage this combination to create mocks and write effective unit tests.
And finally, we explore different ways of converting a List to a Map in Kotlin.