Skip to content

Instantly share code, notes, and snippets.

@LittleHelicase
Last active March 29, 2018 17:52
Show Gist options
  • Save LittleHelicase/3d104d669dac236b90120408734cf32e to your computer and use it in GitHub Desktop.
Save LittleHelicase/3d104d669dac236b90120408734cf32e to your computer and use it in GitHub Desktop.
fun Int?.toString() {
return "42"
}
fun Any?.toString() {
if (this == null) return "null"
return toString()
}
fun main(args : Array<String>) {
val x = null
println(x.toString()) // prints "42" (even though it is not defined as Int?)
val y : String? = null
println(y.toString()) // prints "null"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment