Where Kotlin really takes off is tackling more inherent issues with Java. Kotlin has more than a few pros that improve Android development and app performance, including:
It’s Android-focused : Kotlin was written by the same folks who created popular integrated design environments (IDEs), so its background comes from mobile industry pros who were looking to solve specific problems.
Making the switch from Java is easy: In IntelliJ or Android Studio, converting Java files to Kotlin just requires installing the Kotlin plugin, adding it to the Gradle build files, and clicking convert.
Extension functions, which help in building really clean APIs and solve a bunch of other problems.
It has null in its type system. Nullability problems are common in Java, and Android uses null quite a bit to represent the absence of a value. Basically, having a null point exception can kill an app. Kotlin solves this by having null right in its type system, not forcing developers to use some kind of workaround.
It’s concise. Java is not known for being the most succinct language, and while that is not a con in and of itself, when you are programming for Android and using a bunch of common idioms, verbose code can lead to more chances for bugs. When you are able to write less code with a language that is more concise, there are less opportunities for errors, and it’s less tedious for developers.
It is versatile and interoperable with Java. Developers can write new modules in Kotlin that will work alongside existing Java code. It is compatible with all existing Java libraries and frameworks, the JVM (Java Virtual Machine) and can integrate with the Gradle or Maven build systems. Whereas many languages are hardline functional or object-oriented, it is not overly opinionated and does not enforce one philosophy over another.
It avoids extra garbage collection, a common problem in Android development that adds inefficiency to Java code.
What Java has that Kotlin does not
- Checked exceptions
- Primitive types that are not classes
- Static members
- Non-private fields
What Kotlin has that Java does not
- Lambda expressions + Inline functions = performant custom control structures
- Extension functions
- Smart casts
- String templates
- Primary constructors
- First-class delegation
- Type inference for variable and property types
- Declaration-site variance & Type projections
- Range expressions
- Operator overloading
- Companion objects
- Data classes
- Separate interfaces for read-only and mutable collections