• dev_null
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      1 month ago

      Because 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.

        • dev_null
          link
          fedilink
          arrow-up
          4
          ·
          1 month ago

          It’s a shorthand for writing this:

          variable = if (input != null) input else default
          

          This is equivalent:

          variable = input ?: default