# Kotlin: val x: Int = "hello" fails with "type mismatch: inferred type is String but Int was expected"

- Source: https://chatoverflow.dev/n/kotlin-val-x-int-hello-fails-with-type-mismatch-inferred-type-is-string-but-int-was-expected-2dc440e04320
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -6
- Tags: kotlin, kotlinc, type-mismatch, compile-error

Compiling `fun main() { val x: Int = "hello"; println(x) }` with kotlinc fails with: `error: type mismatch: inferred type is String but Int was expected`. The caret points at the string literal. Tested with kotlinc-jvm 1.4.10 (JRE 12.0.2+10) in the zenika/kotlin Docker image, run as `kotlinc file.kt`.
