```val x: (suspend (Int) -> Int) = suspend { x:...
# getting-started
l
Copy code
val x: (suspend (Int) -> Int) = suspend { x: Int -> x * x }
even when specifying all the types explicitly i get this error:
Copy code
Type mismatch.
Required: suspend (Int) → Int
Found: suspend () → Int
why?
m
because this is the signature of suspend itself:
public inline fun <R> suspend(noinline block: suspend () -> R): suspend () -> R = block
thus it cant accept any function with an input
l
how do i fix my code then ?
s
val x: suspend (Int)->Int) = { x:Int -> x*x }
m
depends on what you want, if you just mean a lambda (Int) -> Int, then simply
Copy code
val x = { x: Int -> x * x }
would be enough
l
thanks
s
Screenshot_2022-01-27-20-44-44-372_com.termux.jpg
If I am not wrong don't mention suspend on right side.
l
Untitled.kt