Kotlin Code Pills — Val / Var

Tugce Konuklar Dogantekin
The Kotlin Chronicle
1 min readApr 3, 2019

In Kotlin, val and var are the two keywords you can use to declare variables.

val is using for Read-Only local variables definition. Means immutable, you can assign only once, which is same as final in Java.

var variable allows to you to reassign a new value and use it.

VAL

Kotlin:

val a:Int = 1

Java:

final int a = 1;

VAR

Kotlin:

var b:Int = 2
b +=1

Java:

int b = 2;
b++;

Tips:

Variable definition formule is :

           (var/val <name>[: <type>][= initialiser])

See you on next pill

--

--