Kotlin Types

Kotlin types are explicit when needed and inferred when obvious. That balance gives you both readability and safety.

Primitive values

val count: Int = 3
val price = 19.99
val active = true

Strings

Kotlin string templates reduce concatenation noise and make formatted output easier to read.

Arrays and values

val numbers = arrayOf(1, 2, 3)
val names = listOf("Ada", "Linus")

Type inference

The compiler can infer many types. Use explicit types when the meaning is not obvious or when public APIs need clarity.

Practice

  1. Write a variable declaration with and without an explicit type.
  2. Build one string template that prints a formatted sentence.
  3. List one case where explicit typing improves a public API.