“Type mismatch: inferred type is String? but String was expected” — the same error, on four lines, in a file that compiled fine an hour ago. Kotlin’s compiler is unusually helpful, but it reports problems at the point where they surface, not where they were created, so the fix is often two functions above the red line. Learning to read a few recurring complaints takes most of the frustration out of the language.
The nullable value that “cannot” be null
This is the one you will meet most. Something returns String? — a map lookup, a find call, a value from Java — and you append !! until it compiles. That works until the day it does not, and then it is a runtime crash instead of a compile error. Fix the source rather than the symptom: give the lookup a default with ?. and ?:, validate input at the boundary where it enters your program, and keep !! for cases where a failure really is a bug you want to hear about.
The other half of this problem comes from Java. Kotlin cannot tell whether a Java method returns null, so it treats the result as a platform type and lets you use it without a check. Mark the value nullable at once with an explicit type, for example val name: String? = legacy.getName(), and the compiler starts helping you again instead of quietly permitting a crash.
Fighting the compiler over val and reassignment
A val is a reference that cannot be reassigned, but the object it points to can still change. New Kotlin developers hit this from both sides: they declare a var list and reassign it in a loop, or they declare a val and are surprised that list.add(...) compiles. Use val with a mutable collection only when you mean to mutate, and prefer building a new list with map or filter — it is shorter and it removes a whole class of aliasing bugs.
Equality, and the data class you forgot
Two instances of a plain class with the same fields are not equal, because == falls back to reference identity. That produces bizarre behaviour in Set, Map and any contains check. If a class is a value — a coordinate, a request, a row from a table — make it a data class and equality follows the fields. Reach for === only when you genuinely care that two references point at the same object.
The lambda that returns the wrong thing
Inside a lambda, a bare return exits the enclosing function, not the lambda, which is why a forEach that “returns early” keeps going. Use return@forEach to leave one iteration, or switch to firstOrNull or takeWhile when the real intent is to stop. Similarly, a lambda whose last expression is an assignment returns Unit, so a map built that way silently produces a list of units.
Blocking the main thread
Code that runs fine in a test can freeze a UI when it does a file read or a network call on the main thread. Move the work into a coroutine with suspend functions and a scope tied to the screen’s lifetime, and keep the update to the UI where it belongs. If a call must block, wrap it and say so.
Fix the cause, not the red line. Almost every one of these complaints is the compiler asking you to be explicit about something that would otherwise become a crash.