4 ms·
Ah, but the ternary operator solution requires repeating the name of the variable twice. And obviously, since you're writing in Java, your variable name will be
by Strilanc 2y ago
Ah, but the ternary operator solution requires repeating the name of the variable twice. And obviously, since you're writing in Java, your variable name will be at least 50 characters long. Thus making `Objects.requireNonNullElse` shorter.
- Glant 2y agoThe null coalescing operator (??) works well for this
- hn_throwaway_99 2y agoExactly, which is why it's baffling that Java doesn't have it.