https://kotlinlang.org logo
#announcements
Title
# announcements
k

koral

03/17/2017, 1:25 AM
I have a function like this:
override fun processNewLines(lines: Array<String>) = lines.forEach { <http://logger.info|logger.info>(it) }
and it works as expected however when I change last invocation to lambda:
override fun processNewLines(lines: Array<String>) = lines.forEach { logger::info }
code compiles fine but there is a runtime error
java.lang.NoSuchMethodError: kotlin.jvm.internal.FunctionReference.<init>(ILjava/lang/Object;)V
at that line
k

kingsley

03/17/2017, 6:15 AM
koral: It should be
lines.forEach(logger::info)
. Notice the paren instead of a curly brace.
logger::info
itself is a function reference, so no need to wrap it inside a lambda
k

koral

03/17/2017, 11:35 AM
👌 thanks
4 Views