How to resolve 'type mismatch in kotlin'?

Example:

val str: String = 123

This error occurs when assigning a value of one type to a variable of another.

Solution:

Ensure that the value being assigned matches the variable's declared type. Consider explicit type casting if necessary.


val number: Int = 123
val str: String = number.toString()

Beginner's Guide to Kotlin