Introduction
Type inference helps the compiler guess the type of a value so you don't have to write it every time. This makes your code shorter and easier to read.
val variableName = value var variableName = value
val number = 10
val name = "Alice"
var price = 9.99
val isActive = true
fun main() { val age = 25 val greeting = "Hello, Kotlin!" var temperature = 36.6 val isSunny = false println("Age: $age") println("Greeting: $greeting") println("Temperature: $temperature") println("Is it sunny? $isSunny") }
type inference mean in Kotlin?result in this Kotlin code?val result = listOf(1, 2, 3).map { it * 2 }val x = null val y = x + 5
data? val data = mapOf("a" to 1, "b" to 2).mapValues { it.value * 10 }Pass the test and this pattern moves unknown