This code compiles ```val xyz: Map<String, (Str...
# announcements
a
This code compiles
Copy code
val xyz: Map<String, (String) -> Unit> = mapOf("abc" to { it -> println(it.length) })
with a suggestion that there is a 'redundant lambda arrow' (the
it ->
part in the lambda in the map key). However, if I remove that portion, I get a 'type inference failed' compile error. The compiler interprets the lambda as
() -> ???
rather than
(String) -> Unit
. Shouldn't the compiler interpret
{ println(it.length) }
as satisfying
(String) -> Unit
?
m
Hmm, it could infer it so may be a shortcoming of the compiler. See if there's an existing issue for this and create one of their isn't? If you give the parameter a name other than
it
, you won't get the warning.