Variables & Types in Kotlin

From the Kotlin cheat sheet · Getting Started · verified Jul 2026

Variables & Types

Variable declarations and basic types

kotlin
// Immutable variable (read-only)
val name: String = "Kotlin"
val age = 25  // Type inference
// name = "Java"  // Error: Val cannot be reassigned

// Mutable variable
var count = 0
count++  // OK
count = 10  // OK

// Basic types
val byte: Byte = 127
val short: Short = 32767
val int: Int = 2147483647
val long: Long = 9223372036854775807L
val float: Float = 3.14f
val double: Double = 3.141592653589793
val boolean: Boolean = true
val char: Char = 'K'
val string: String = "Hello, Kotlin"
💡 Use val by default, var only when mutability is needed
⚡ Type inference makes explicit types often unnecessary
📌 const val for compile-time constants, val for runtime constants
🟢 lateinit for non-null properties initialized after construction

More Kotlin tasks

Back to the full Kotlin cheat sheet