Why Kotlin for Android development
Kotlin is an open-source, statically typed programming language which combines object-oriented and functional programming features.
Why Kotlin for Android development

Kotlin is an open-source, statically typed programming language which combines object-oriented and functional programming features.
When Google announced that, Android will be Kotlin first in Google I/O 2019, all the developers have been wondering why we should be moving Kotlin. If you are one of them this article may provide some insights to understand better.
https://developer.android.com/kotlin/first
Advantages of using Kotlin in your Android project:
- Improved Compiler
- Readability & Reduced Boiler plate code
- Null-safety
- Interoperable
- Concurrency
- Jetpack Compose
- Lightweight compiler plugins
- No Raw Types
- Data Class
- Extension functions
- Function types
- Gradle KTS
- Immutability
Let’s look at them in detail below.
- Improved Compiler Kotlin compiler is smarter, It detects errors at compile time, not at runtime, leveraging the “fail-fast” principle. Compiler performs lots of checks, reduces runtime errors & the number of bugs in the code.
Google & JetBrains have been working on optimising the compile time. Let’s take a look at the approaches that they have taken to optimise the compiler.
1. Incremental compilation — only recompile affected files.
2. Compile avoidance — only recompile affected modules.
Gradle supports compile avoidance out-of-the-box. Kotlin Gradle plugin brings a somewhat limited implementation of incremental compilation to Gradle.
- Readability & Reduced Boiler plate code Kotlin has high readability and precision which makes it easier to understand the program. A Java developer should be easily able to grasp Kotlin very quickly. The boiler plate code have been reduced after migration to Kotlin.
Java:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
Kotlin:
button.setOnClickListener {
}
- Null-safety In Java if we try to try access members of a null variable, then we will get NullPointerException. In Kotlin, We can’t access the value without doing a null check.
Java:
String s;
s.length(); // Will throw an Exception
Kotlin:
s?.length // Will not throw an Exception
Will reduce the number of crashes by at least 20% my mandating the safety checks.
- Interoperable Kotlin is Interoperable, we can use all the pre-existing libraries and modules in a Kotlin project. Can also be used along with existing java classes.
- Concurrency Kotlin runtime doesn’t encourage a classical thread-oriented concurrency model with mutually exclusive code blocks and conditional variables, as this model is known to be error-prone and unreliable. Kotlin provides a couple of alternative approaches, allowing us to use hardware concurrency and implement blocking IO.
Coroutines are one such suggested approach, they are very light-weight threads that can be used to perform a CPU-intensive work and network I/O or a long-running operations
Coroutines are stack-less, which means they demand lower memory usage as compared to threads.
Coroutines are able to perform long-running and cpu intensive tasks by suspending execution without blocking the current thread and then resuming the execution at a later time, which allows the creation of non-blocking asynchronous code that appears to be synchronous.
To read more about coroutine flows and channels(docs)
- Jetpack Compose A modern toolkit for building native Android UI.
setContent {
Text(“Hello world!”)
}
Will display a TextView in the screen with content “”Hello World”
- Lightweight compiler plugins Kotlin provides ksp(Kotlin symbol processor) a light weight compiler plugin developer tool. Although it is not a stable version likely to change. To read more on ksp (docs)
- No Raw Types Kotlin has removed the support for Raw Types(int, boolean, etc) hence produces a more type-safe code. The ClassCastException can occur at runtime with Raw types, Kotlin tries to capture these errors in Compile time itself.
- Data Class New Data class to hold data.
Kotlin:
data class Employee(val name: String, val age: Int)
Compiler takes care of deriving toString(), equals(), hashCode(), and copy() functions unless an explicit implementation is provided.
Java:
class Employee {
String name;
String age;
void getName() {
}
void setName() {
}
}
- Extension functions Kotlin gives the programmer the ability to add more functionality to the existing classes, without inheriting them. Which is achieved through extensions. When a function is added to an existing class it is known as Extension Function.
inline fun <reified T : Activity> Context.startActivity(block: Intent.() -> Unit = {}) {
startActivity(Intent(this, T::class.java).apply(block))
}
Simple using:
startActivity<AnyActivity>()
With extras:
startActivity<AnyActivity>{
putExtra("data", "<value>")
}
- Function types Kotlin functions are first-class. A function can be stored in a data structures and variables, which can be passed as arguments to or returned from other higher-order functions. functions can be operated in the same ways as non-function values. Kotlin makes use of a range of function types for representing functions. Moreover, it comes with a set of specialised language constructs, such as the lambda expressions. Anonymous functions and lambda expressions need not declared but passed immediately as an expression.
- Gradle KTS So far we have been using groovy for our build configurations and project setup. Kotlin DSL primer can been used in place of groovy.
To know why we need to migrate to kts we will look at the advantages that are provided by kts,
* auto-completion and content assist
* quick documentation
* navigation to source
* refactoring, etc.
If you would like to migrate to kts(docs)
- Immutability An immutable objects state cannot be changed once it is created. Immutable objects are thread safe. Can help us avoid race conditions & concurrency problems. Kotlin suggests the usage of val where immutability is needed, as compiler can help us with throwing errors at compile time rather than we figuring out something changed at a later point.
Conclusion
Kotlin is concise and easy to understand. Although it can be bit confusing at the beginning as we try to progress it will be easier to get the hang of it. I would recommend people to understand, learn and use it in your new project. Kotlin offers some more features which I may not have covered as part of this article. As for coroutines and flow which I will try to cover in the next article.
Please leave your comments and suggestions.
메타데이터
- post_id
- 91985d124e0e
- slug
- why-kotlin-not-java-for-android-91985d124e0e
- url
- https://medium.com/@1ok1/why-kotlin-not-java-for-android-91985d124e0e
- canonical_url
- https://medium.com/@1ok1/why-kotlin-not-java-for-android-91985d124e0e
- author_url
- https://medium.com/@1ok1
- status
- ok
- fetched_at
- 2026-06-09 18:04:40