What does 'type mismatch: inferred type is x? but x was expected' in kotlin mean?

This error suggests that you're dealing with a nullable type (X?) when a non-nullable type (X) is expected.


val name: String? = null
fun greet(n: String) = "Hello, $n"


val name: String? = "John"
fun greet(n: String) = "Hello, $n"
name?.let { greet(it) }
Use safe calls and other null-safety mechanisms to handle nullable types.

Beginner's Guide to Kotlin