eygraber
12/20/2018, 6:53 PMor
instead of ?:
for null coalescing and I found some interesting results.
Here's the extension:
infix fun <A> A?.or(that: A): A = this ?: that
I wrote a small snippet to validate this which works fine:
val s: String? = null
val a = s or ""
Then I wanted to test conflicts with Int.or
and so I changed my snippet to:
val s: Int? = null
val a = s or ""
I expected an error saying something along the lines of or expects an Int
but to my surprise it compiled fine. I plugged it into the kotlinc repl (is is technically a repl?) and printed a
. It was an empty string 🤯
Then I printed a.javaClass
and it was String
🤯 🤯 🤯
Am I missing something here? I wanted to search the issue tracker, but I can't even figure out what to search for.