Kotlin Puzzlers -1

代码:

fun hello() = {
    println("Hello, World")
}
hello()

运行后输出什么呢?
a. Does not compile
b. Prints “Hello, World”
c. Nothing
d. Something else

答案: C

解释:
hello is a function that returns function created using lambda expression. It’s just returning function. To print text, we need to invoke it:
hello()()
Prints: Hello, World

for more Puzzlers:
http://portal.kotlin-academy.com/#/?tag=puzzler-1

推荐阅读更多精彩内容