Kotlin Variables
Hello, My name is Mansi. I have over 3 years of professional experience developing high-quality Android applications.
Search for a command to run...
Hello, My name is Mansi. I have over 3 years of professional experience developing high-quality Android applications.
No comments yet. Be the first to comment.
Kotlin is a modern programming language that was first introduced by JetBrains in 2011. Since then, Kotlin has gained a lot of popularity among developers due to its concise syntax, null safety, and interoperability with Java. One of the most importa...

Now that almost all Android developers have switched from Java to Kotlin, they are finding how much easier, cleaner, and more concise Kotlin is than Java. Kotlin introduces a number of developer-friendly features for less code, reducing the number of...
In this blog, we will learn about the lateinit vs lazy properties in Kotlin. In Kotlin, there are two ways to initialize a property that is not available at the time of object creation: lateinit and lazy. Both of these keywords allow you to postpone ...
In this blog, we will discuss the difference between AndroidViewModel and ViewModel. In the Android Jetpack architecture components, ViewModel and AndroidViewModel are two classes that are used to manage UI-related data across configuration changes. ...

In this article, we are going straight to the point. 🚀 I want to share some extension functions to make your experience with the Firebase Database a little more comfortable with Kotlin. We are going to make reusable code that is also going to avoid ...
A variable refers to a memory location that stores some data.
You can declare variables in Kotlin using the val and var keywords.
val:
A variable declared with the val keyword is read-only (immutable). It cannot be reassigned after it is initialized.
val name = "Kotlin"
name = "Language" //Error: val can not be reassigned
It is similar to the final variable in Java.
var:
Variable declared using var keyword is mutable. It can be reassigned after it is initialized.
val name = "Kotlin"
name = "Language" //No error. It works
It is similar to regular variable in Java.
Type inference:
In Kotlin, it is not mandatory to explicitly specify the type of variable that you declare. The Kotlin compiler will automatically infer the type of the variable from the initialized section.
val name = "Kotlin" // type infered as "String"
val value = 100 //type infered as "Int"
You can also explicitly define the type of the variable.
val name: String = "Kotlin"
val value: Int = 100
Type of the variable declaration mandatory if you dont initialize the variable.
val name // Error: variable must either have a Type annotation or be initialized
name = "Kotlin"
You can also declare something like this.
val name: String //works
name = "Kotlin"