美文网首页
Kotlin Puzzlers -1

Kotlin Puzzlers -1

作者: vb12 | 来源:发表于2021-09-03 10:10 被阅读0次

代码:

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

相关文章

网友评论

      本文标题:Kotlin Puzzlers -1

      本文链接:https://www.haomeiwen.com/subject/vuohwltx.html