- The variable cannot be changed once the value is assigned. It is similar to final variable in Java. • var - Mutable reference - The variable can be changed later in the program. It corresponds to regular Java variable.
- The variable cannot be changed once the value is assigned. It is similar to final variable in Java. • var - Mutable reference - The variable can be changed later in the program. It corresponds to regular Java variable.
references and non-nullable references. • User explicitly checks for a null in conditions • Using a Safe Call Operator ?. • Elvis Operator ?: : If reference to a val is not null, use the value, else use some default value that is not null
references and non-nullable references. • User explicitly checks for a null in conditions • Using a Safe Call Operator ?. • Elvis Operator ?: : If reference to a val is not null, use the value, else use some default value that is not null
references and non-nullable references. • User explicitly checks for a null in conditions • Using a Safe Call Operator ?. • Elvis Operator ?: : If reference to a val is not null, use the value, else use some default value that is not null
references and non-nullable references. • User explicitly checks for a null in conditions • Using a Safe Call Operator ?. • Elvis Operator ?: : If reference to a variable is not null, use the value, else use some default value that is not null
-> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i) // Outputs -> 8, 6, 4, 2 for (i in 0 until array.length) { array[i] //Everything works } for (i in 'a'..'c') print(i)
-> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i) // Outputs -> 8, 6, 4, 2 for (i in 0 until array.length) { array[i] //Everything works } for (i in 'a'..'c') print(i) // Outputs -> 'a', 'b', 'c'
val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" var flavorString: String? } // ERROR: Property must be initialized or be abstract.
val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" var flavorString: String? } // ERROR: Property must be initialized or be abstract.
val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" val flavorString: String? } // ERROR: Property must be initialized or be abstract.
val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" val flavorString: String? init { flavorString = "I taste like $flavor" } }
val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" val flavorString: String? init { flavorString = "I taste like $flavor" } }
"Vanilla", val cone: Boolean = true){ val isVanilla = false get() = this.flavor == "Vanilla" } // ERROR - Initializer is not allowed here because // this property has no backing field
private - visible inside the file/class containing the declaration • internal - visible inside the same module • protected - visible inside the class and its subclasses
private - visible inside the file/class containing the declaration • internal - visible inside the same module • protected - visible inside the class and its subclasses
private - visible inside the file/class containing the declaration • internal - visible inside the same module • protected - visible inside the class and its subclasses
private - visible inside the file/class containing the declaration • internal - visible inside the same module • protected - visible inside the class and its subclasses