I just tried writing an extension to use `or` inst...
# announcements
e
I just tried writing an extension to use
or
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:
Copy code
val s: String? = null
val a = s or ""
Then I wanted to test conflicts with
Int.or
and so I changed my snippet to:
Copy code
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.