How Kotlin can cover for the shortcomings of Java? — A Developer’s Outlook

Android App Development with Kotlin — Systango Blog

Merits of Kotlin

  • Concise — You can “do more with less code”. As a result, your code will be easy to use and easy to change.
  • Enforces best practices — While declaring a field, you have to specify val or var before it to decide whether it is mutable or immutable. By default every class in Kotlin is final. To allow inheritance, you have to specify a class as open explicitly.
  • Has both OO and FP style — Kotlin is not a fully object-oriented language. You can use it as object-oriented or you can write your code without using classes also.
  • Interoperable with Java — Java code can be used in Kotlin and Kotlin code can be used in Java. Also, it’s easy to convert Java code into Kotlin using Android Studio or various online converters. To use Kotlin in existing Java project, you don’t need to rewrite everything from scratch. You can start writing new classes in Kotlin and if needed, can convert existing Java code to Kotlin gradually.
  • User-friendly Keywords — Kotlin replaced switch statement with when. Similarly, introduced “is” instead of instanceof. Kotlin comes with real-life keywords which makes the program more expressive.

Cool features of Kotlin

  • Easy Null Pointer Handling — As discussed initially, Kotlin provides easy Null Pointer Exception handling without using too many null checks. If there is any chance of null pointer exceptions, Kotlin compiler will give you an error at compile time. It provides safe-calls, non-null assert and Elvis operator to deal with null values.
  • Smart Cast — Let’s look at the example below:
Code — Android App Development with Kotlin — Systango Blog
Code — Android App Development with Kotlin — Systango Blog
  • Data Classes — To create POJO or Model or Data Holder classes, you do not need to write lots of boilerplate code i.e. getters/setters, toString(), equals(). Though Java has libraries like Lombok for this purpose, Kotlin comes with first-class support of data classes.
  • Easy Singleton — We will see the singleton with the undermentioned example:
Code — Android App Development with Kotlin — Systango Blog
Code — Android App Development with Kotlin — Systango Blog
Code — Android App Development with Kotlin — Systango Blog
Code — Android App Development with Kotlin — Systango Blog

Where to Use?

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
SYSTANGO

SYSTANGO

London’s leading digital agency Systango offers full service from strategy, scoping to launch & maintenance, innovative campaigns to enterprise infrastructure.