Skip to content

Instantly share code, notes, and snippets.

@himattm
Last active October 13, 2021 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save himattm/9e2a61c2ebce53aacf3a670960765e5b to your computer and use it in GitHub Desktop.
Save himattm/9e2a61c2ebce53aacf3a670960765e5b to your computer and use it in GitHub Desktop.
Today we have a Kotlin brain teaser! What does this code print?
data class Foo(val i: Int)
fun main() {
val map = mapOf(
1 to Foo(1),
2 to Foo(2),
3 to Foo(3),
)
println("map = $map")
println("map[1] is Foo = ${map[1] is Foo}")
println("map[0] is Foo = ${map[0] is Foo}")
println("map[0] is Foo? = ${map[0] is Foo?}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment