Static typing determines every expression’s type at compile time. Kotlin’s compiler checks that accessed fields and methods exist and that function results have expected types, catching many errors before execution. section 1.2 section 1.2.2
val x: Int = 1 #1 val y = 1 #2
Kotlin often infers a variable’s type from its initializer, so explicit annotations and compile-time type information coexist. section 1.2.2
Static typing supports several practical benefits:
- Performance: method calls do not require determining the target method at run time. section 1.2.2
- Reliability: compiler checks reduce inconsistent operations and some run-time crashes. section 1.2.2
- Maintainability and tool support: visible types assist unfamiliar-code navigation, refactoring, completion, and other IDE features. section 1.2.2
Static dispatch of extension functions
A variable declared as View can hold a Button, but extension resolution uses the variable’s declared static type: fun View.showOff() = println("I'm a view!") fun Button.showOff() = println("I'm a button!") val view: View = Button() view.showOff() // I'm a view! Regular overridden members dispatch differently: view.click() invokes Button.click(). Kotlin extensions compile to static Java functions, reinforcing that their receiver type is selected at compile time. section 3.3.4
Kotlin also uses its type system for safety. Nullable types are marked with ?, and the compiler rejects operations that could produce a NullPointerException. Type checks such as is allow safe member access after the check. section 1.4.3











