Posts

Showing posts from November, 2023

Kotlin Crash course

 Kotlin var greeting: String = "Hi" val name: String = "Malathi" we can reassign value to variable defined using var but not val. By default Strings in Kotlin are non null values. To make them nullable, we should use ? operand like below val name: String? = "Malathi" Ex: fun main() {    var greeting: String = "Hi"    val name: String = "Malathi"    println(greeting)    println(name) } Kotlin has type inference. It means that the type is automatically detected based on the value assigned to the variable. So var greeting = "Hi" statement too works. Control loops if statement: if(greeting != null) { println("if statement")} while statement: It is similar to Switch statement in Java while(greeting) {    null -> println("Hi")    else -> println(greeting) }  val greetingToInvite = if(greeting != null) greeting else "Hi" println(greetingToInvite) val greetingToInvite = when(greeting) {    null -...