Defining variables

In Kotlin, we can define a read-only variable using the val keyword, and we can use the var keyword for mutable variables. In Kotlin, a variable can be defined as a first class citizen, meaning that we don't have to create a class of a function to hold variables. Instead, we can declare them directly in a file.

The following example shows how to define read-only and mutable variables:

val readOnly = 3
var mutable = 3
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.2.157