My Code ```fun changeIntToDouble(number: Int) { ...
# getting-started
m
My Code
Copy code
fun changeIntToDouble(number: Int) {
    return number.toDouble()
}
but my ide said Type mismatch: inferred type is Int but Unit was expected How can I fix it?
r
If you don't explicitly specify a return type it defaults to
Unit
, i.e. "nothing". You need to explicitly define it as:
Copy code
fun changeIntToDouble(number: Int): Double {
v
Or write it as expresssion body like
Copy code
fun changeIntToDouble(number: Int) = number.toDouble()
r
^ That works too, although my understanding is that too many inferred return types can make IntelliJ slow.