# Elvis Operator

Published articles for Elvis Operator.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Nullability in Kotlin

DevFeed: [Nullability in Kotlin](<https://devfeed.tech/articles/nullability-in-kotlin-39336.md>)

Original publisher: [Read original article](<https://kt.academy/article/kfde-nullability>)

Published: 2023-03-13T00:01:00Z

Content type: tutorial

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Null-Safety](<https://devfeed.tech/topics/null-safety.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [Java](<https://devfeed.tech/topics/java.md>)

Tags: [elvis-operator](<https://devfeed.tech/tags/elvis-operator.md>), [exception](<https://devfeed.tech/tags/exception.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [null-safety](<https://devfeed.tech/tags/null-safety.md>), [safety](<https://devfeed.tech/tags/safety.md>), [type](<https://devfeed.tech/tags/type.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This tutorial explains Kotlin null-safety and how nullable values are handled. It describes explicit values and nullable types, then introduces safe calls, not-null assertions, smart casts, and the Elvis operator.

### Source excerpt

How Kotlin null-safety works, and how can we deal with nullable values.

## Effective Kotlin Item 10: Design for readability

DevFeed: [Effective Kotlin Item 10: Design for readability](<https://devfeed.tech/articles/effective-kotlin-item-10-design-for-readability-39288.md>)

Original publisher: [Read original article](<https://kt.academy/article/ek-readability>)

Published: 2022-10-24T00:00:00Z

Content type: tutorial

Language: en

Sources: [Kt. Academy](<https://devfeed.tech/sources/kt-academy.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Kotlin programming](<https://devfeed.tech/topics/kotlin-programming.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [cognitive-load](<https://devfeed.tech/tags/cognitive-load.md>), [effective](<https://devfeed.tech/tags/effective.md>), [elvis-operator](<https://devfeed.tech/tags/elvis-operator.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [junior](<https://devfeed.tech/tags/junior.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [readability](<https://devfeed.tech/tags/readability.md>), [workshop-learning-programming](<https://devfeed.tech/tags/workshop-learning-programming.md>)

### AI overview

This article explains why code readability matters in Kotlin, emphasizing that developers spend much more time reading code than writing it. It argues that fewer lines or characters do not necessarily make code easier to understand, and that readability depends on cognitive load and familiarity with programming idioms, especially for less experienced Kotlin developers.

### Source excerpt

Do we really want out applications concise, or do we rather want them readable?

## Nulls and Null Safety

DevFeed: [Nulls and Null Safety](<https://devfeed.tech/articles/nulls-and-null-safety-25061.md>)

Original publisher: [Read original article](<https://typealias.com/start/kotlin-nulls/>)

Author: author@typealias.com (Dave Leeds)

Published: 2021-03-30T00:00:00Z

Content type: tutorial

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>)

Tags: [elvis-operator](<https://devfeed.tech/tags/elvis-operator.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [learn-to-program](<https://devfeed.tech/tags/learn-to-program.md>), [not-null-assertion-operator](<https://devfeed.tech/tags/not-null-assertion-operator.md>), [null](<https://devfeed.tech/tags/null.md>), [null-safety](<https://devfeed.tech/tags/null-safety.md>), [optional](<https://devfeed.tech/tags/optional.md>), [programming](<https://devfeed.tech/tags/programming.md>), [safe-call-operator](<https://devfeed.tech/tags/safe-call-operator.md>), [smart-cast](<https://devfeed.tech/tags/smart-cast.md>)

### AI overview

An introduction to nulls and null safety in Kotlin, explaining that variables may not always hold a value and setting up a coffee-rating example implemented in Kotlin.

### Source excerpt

So far in this book, every time that we created a variable, whether it was a String, an Int, or a Boolean, we assigned a value to it. There are times, though, when we need to create a variable that might not actually hold a value! This brings us to the exciting topic of nulls! Introduction to Nulls James has set up a coffee stand downtown, and he's ready to start sharing his fine brew!

## The hidden pitfalls of the Elvis operator

DevFeed: [The hidden pitfalls of the Elvis operator](<https://devfeed.tech/articles/the-hidden-pitfalls-of-the-elvis-operator-25887.md>)

Original publisher: [Read original article](<https://medium.com/google-developer-experts/the-hidden-pitfalls-of-the-elvis-operator-da536ba68161?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2020-07-28T08:05:18Z

Content type: tutorial

Language: en

Sources: [Stories by Danny Preussler on Medium](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [elvis-operator](<https://devfeed.tech/tags/elvis-operator.md>), [expression](<https://devfeed.tech/tags/expression.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [null-safety](<https://devfeed.tech/tags/null-safety.md>), [pitfalls](<https://devfeed.tech/tags/pitfalls.md>), [programming](<https://devfeed.tech/tags/programming.md>), [returning](<https://devfeed.tech/tags/returning.md>)

### AI overview

This Kotlin article explains that the Elvis operator can behave differently from an equivalent if/else statement when chained expressions are involved. Kotlin evaluates the full expression on the left, including the final function call, before deciding whether to evaluate the Elvis branch, so both functions may be called when the final expression returns null.

### Source excerpt

Hidden pitfalls when using Elvis operator I guess many of us love Elvis, both the artist and the operator in Kotlin. But it can lead to some hidden pitfalls if you are not aware of how it works. https://unsplash.com/photos/1LCzr14Ah5U I only realized recently when Vladimir Zdravkovic put some code on twitter and ask us to guess what it's printing: https://twitter.com/vlazdra/status/1287366531987406848?s=20 I assumed a hidden puzzle but I could not see the issue. I could not see any reason why this would print anything but it does! After thinking about the issue (Vladimir wrote an article about it) I found more and more cases where this could go wrong. But let me show you some code: Kotlin's null safety I think most of us love the way we can easily write null safe code with Kotlin like this: presenter?.onDestroy() or data?.let{ updateData(data) } And it is super easy to add an alternative case: data?.let{ updateData(data) } ?: run { showLoadingSpinner() }Let me ask you something Do you think the following code is basically the same as the above? if (data != null) { updateData(data) } else { showLoadingSpinner() } I'm sure most of us do think they are equivalent. But what if I told you, it's not? The if/else is totally binary, it's either-or. But with the Elvis operator, it might be both! To understand why we have to look closer to how it works. Other than the else that belongs explicit to an if , the Elvis operator is not tied to a single ?. Remember, we can chain them: someVariable?.someField?.doSomething() if we now add the Elvis operator here, it will get executed depending on the expression to its left side: someVariable?.someField?.doSomething() ?: run { doSomethingElse() } so if any expression in there is null, the Elvis block will get called. It will finish evaluating everything on the left before checking if the operator is needed. This includes the last expression. So this is depending on whatever doSomething() returns! If it is null, then the right side wil

## Understanding Nullability In Kotlin

DevFeed: [Understanding Nullability In Kotlin](<https://devfeed.tech/articles/understanding-nullability-in-kotlin-22845.md>)

Original publisher: [Read original article](<http://androidessence.com/understanding-nullability-in-kotlin/>)

Author: Adam McNeilly

Published: 2017-06-28T00:00:00Z

Content type: tutorial

Language: en

Sources: [Android Essence](<https://devfeed.tech/sources/android-essence.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [elvis-operator](<https://devfeed.tech/tags/elvis-operator.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [null](<https://devfeed.tech/tags/null.md>), [null-safety](<https://devfeed.tech/tags/null-safety.md>)

### AI overview

This tutorial explains Kotlin's nullability and null-safety features for Java programmers. It covers nullable and non-nullable types, explicit null checks, the safe operator, and the Elvis operator, while noting that Java interoperability can still allow NullPointerException risks.

### Source excerpt

Every Java programmer has faced the dreaded NullPointerException at some point in their life. Sometimes it's your fault, sometimes it's a pesky race condition. Regardless, it's a head ache and generally leads to a ton of if (myVariable != null) { } conditions all over your code. However, the latest craze Kotlin can help with that too. Kotlin introduced null safety into its type system, with the potential of removing all NPEs. This post is both going to review the official docs linked above, as well as provide some common tips and tricks to work with the nullability - something that is new in this language for many Java programmers.

## How To Build A Todo List In Kotlin Part 4: Storing Items

DevFeed: [How To Build A Todo List In Kotlin Part 4: Storing Items](<https://devfeed.tech/articles/how-to-build-a-todo-list-in-kotlin-part-4-storing-items-22814.md>)

Original publisher: [Read original article](<http://androidessence.com/how-to-build-a-todo-list-in-kotlin-part-4-storing-items/>)

Author: Adam McNeilly

Published: 2017-05-21T00:00:00Z

Content type: tutorial

Language: en

Sources: [Android Essence](<https://devfeed.tech/sources/android-essence.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Android](<https://devfeed.tech/topics/android.md>), [App](<https://devfeed.tech/topics/app.md>), [data](<https://devfeed.tech/topics/data.md>), [Streams](<https://devfeed.tech/topics/streams.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-studio](<https://devfeed.tech/tags/android-studio.md>), [app](<https://devfeed.tech/tags/app.md>), [code](<https://devfeed.tech/tags/code.md>), [data](<https://devfeed.tech/tags/data.md>), [elvis-operator](<https://devfeed.tech/tags/elvis-operator.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [smart-cast](<https://devfeed.tech/tags/smart-cast.md>), [streams](<https://devfeed.tech/tags/streams.md>), [syntax](<https://devfeed.tech/tags/syntax.md>)

### AI overview

A Kotlin tutorial explains how to persist items in an Android todo list application by writing tasks to a text file and reading them back. It also discusses updating storage during activity lifecycle events and briefly explains Kotlin streams, smart casts, and the elvis operator.

### Source excerpt

If you've been following along with parts 1-3, you now have an (almost) working todo list application. The only thing we are missing is persisting the data. Running your Android app now and rotating your screen will show you that the items you add won't persist, and disappear anytime an activity is killed and recreated. This post will show you how to write the list to a text file and read from it.