+ 2
Can anyone tell me difference between val and var in kotlin in simple term
I tried to understand a lot. I try to understand this on other platforms too, i bought a book programing kotlin to understand this but i am not getting the point. i tried everything please tell me how to use it and where to use it in very simple language. example will be appreciated
2 Respuestas
+ 10
Goutam Malviya this may help you 👇👇👇
https://www.sololearn.com/learn/6381/?ref=app
+ 9
Simply: var is used when the value is going to change. val when it isn't (constant.) Personally, until you understand it, code everything val. The compiler will complain, when it must be var and you should change it. Since the IntArray class doesn't change, the following is fine.
val arr = arrayOf(1, 2)
arr[0] = 3