In this video, Annyce covers the most exciting features of the Kotlin programming language. Learn what makes Kotlin so enjoyable to work with; such as its conciseness, safety, and Java interoperability.
- [Instructor] Let's take a look at some of the highlights of the Kotlin programming language. Kotlin is a statically typed language. This means that the types of every expression is known at compile time. This allows the compiler to perform verification on your behalf, which reduces crashes and runtime. This also allows for better code completion when working with any modern IDE. It also allows for refactoring support when you need to make future changes.
Ultimately, it should be possible to use Kotlin in each component of a modern application, whether it's the back end, web, or mobile. Another feature of Kotlin is its concise nature. In this sample code, we're declaring a data class which contains properties for a particular user, their name, age, and email address. Not only is the code minimal, but behind the scenes, a Kotlin compiler generates the necessary constructors, getters, and setters and more.
The language is also safe, meaning that it helps you to avoid common pitfalls when programming. One way it does this is by tracking values that can and cannot be null. In this example, the first variable declared name can be null. Notice the use of the question mark after string. However, that second variable cannot be null. Attempting to set it to null will cause an error. Another benefit of Kotlin is that it supports functional programming.
Functional programming is becoming very popular in the tech space. It has several benefits, such as conciseness, multithreading, and easier testing. This is due to the use of first class and pure functions, as well as immutability of objects. Here's an example of a lambda expression. It takes in the numbers X and Y and it performs multiplication on them. This can be passed around as a value, perhaps input to a function.
Here's another example of how Kotlin supports functional programming, and that's by means of functional style methods available on objects and collections. In this case, we're mapping the list of numbers to a new list, which has the values doubled. Finally, the interoperability with Java is where Kotlin really shines. You can use existing Java methods and classes in your Kotlin code and vice versa.
And if you use the Kotlin tooling, you can navigate effortlessly between your various files. Now, let's take a look at some of the specific advantages of Kotlin on Android.
- What Kotlin has to offer
- Working with lambdas
- Common Android extension functions
- Kotlin Android Extensions overview
- Making use of the Anko library
- Working with coroutines
- Nullability and collections