Skip to content

Instantly share code, notes, and snippets.

@objcode
Last active September 29, 2017 00:02
Show Gist options
  • Save objcode/d1dbeb96d5999c8741d990e057165839 to your computer and use it in GitHub Desktop.
Save objcode/d1dbeb96d5999c8741d990e057165839 to your computer and use it in GitHub Desktop.
Kotlin type puzzle
// In the following declaration, what happens when you call fn()?
val fn: () -> Unit = { "I am not a string" }
// Due to inference, the lambda is evaluated to return Unit and the string is discarded. It is as if you typed,
fun fn(): Unit {
"I am not a string"
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment