How I changed my mind to switch from Java to Kotlin
Hello to everyone. After several years as an Android developer, I decided to give my contribution by writing. This is my first post, so do not prejudge.
Long ago, Google stated that Kotlin would be the official language for Android, and they say that Java can convert 100% to Kotlin. All developers were enthusiastic about this. I did not agree because I thought as long as JAVA works well and the code could be converted to the Kotlin then why should we write our apps in the Kotlin?!
At that time I was skeptical and I continued with java. But today, I have another thought for the choice of Kotlin.
Here are some reasons why we shouldn’t write Java code anymore:
1. Less of code, so that means it is easier to read, maintain and modify
2. Kotlin is a very simple language to learn and has a simple syntax.
3. Kotlin provides null safety.
We all know that the main cause of our crash application is null pointer exceptions. Less crashes with Kotlin means that our applications will be of better quality.
4. Smart cast
In Java we have to manually convert variables. Kotlin compiler tracks your logic and auto-casts types if possible.
5. Model Objects
For building a model class in java we need to have constructors, get and set methods, making a class with many rows of code. In Kotlin, if we build a class model, just one line of code.
6. Removal of findByViewId Boilerplate
With Kotlin we don’t need to declare our object and then apply the “findViewById“ method. We can write the direct id of the widget. In this way we eliminate using a library such as butterknife.
7. The “when” expression
In Kotlin, the “when” expression replaces the switch statement, thereby making the code shorter.
Above I have written some of the reasons why we should write all our application in Kotlin.
Any feedback is welcome.