what is the difference var and val in kotlin
variables defined with var are mutable(Read and Write)
variables defined with val are immutable(Read only)
what is the difference var and val in kotlin
variables defined with var are mutable(Read and Write)
variables defined with val are immutable(Read only)
what is difference between val and var kotlin
// Kotlin difference between val and var
// val stands for read-only variable, and cannot be changed. (immutable variable)
fun main() {
val number = 1
number = 2 // Not possible.
}
// var stands for variable, and can be changed. (mutable variable)
fun main() {
var number = 1
number = number + 9
println(number) // this would return 10, because number got changed
}
kotlin difference between val and var
// Kotlin difference between val and var
// val stands for value, and cannot be changed. (immutable variable)
fun main() {
var number = 1
}
// var stands for variable, and can be changed. (mutable variable)
fun main() {
var number = 1
number = number + 9
println(number) // this would return 10, because number got changed
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us