You're viewing a single thread.
I don't understand this. Small brained users rise up
12 0 ReplyOn the left you have Elvis Presley, while on the right there's the so-called Elvis operator
12 0 Replywhy would you call it anything other than the ternary operator
3 0 ReplyBecause it's not one. Ternary operator is A ? B : C, Elvis operator is A ?: B. The same two characters are involved, but both the syntax and effect is different.
3 0 ReplyThe second one isn't valid syntax in any programming language I'm familiar with. What does it do?
2 0 ReplyIt's a shorthand for writing this:
variable = if (input != null) input else default
This is equivalent:
variable = input ?: default
4 0 ReplyHuh. Neat feature. That's in C# I assume?
2 0 ReplyIt's in Kotlin and some other languages. C# has it but there it's actually
A ?? B
.2 0 Reply
Read further down on my other comment to understand, it's just how the operator looks
2 0 Reply