1.

Where should I use var and where val?

Answer»

In Kotlin, you should use var where the value of the variable is changing very frequently. A good EXAMPLE would be getting the location of an android device: var integerVariable : Int? = null

Whereas, Val should be used in a case where there would be no change of value throughout the whole CLASS. For example, setting the value of text view or MAYBE a BUTTON’s text through CODE:

val stringVariables : String = "Button's Final Text"



Discussion

No Comment Found