NVL-ish guy in Java

I tried Oracle's NVL-like guy (transmitted) in Java. If it is non-null, it will be displayed as it is, and if it is null, a specific character string will be displayed.

Below, commons-lang3-3.5 is used.

Sample1.java


String s = null;

String result = ObjectUtils.defaultIfNull(s, "Slimy");
System.out.println(result); //=>Slimy

If you know it, you can write it in one line. The code that actually comes up from the programmer is like this ↓.

Sample2.java


String s = null;

//Those who are still better
if (s == null) {
    s = "Slimy";
}
System.out.println(s); //=>Slimy

If you carelessly like this ↓.

Sample3.java


String s = null;

//Please stop
if (s == null) {
    System.out.println("Slimy");
} else {
    System.out.println(s);
}

If this is an input value, about 100 samples like Sample3 will be mass-produced, and then it will be uncontrollable anymore. Who will review it? I want you to do your best and stop mass-producing fucking code ...

Recommended Posts

NVL-ish guy in Java
Perl's grep-ish guy in Java
Partization in Java
Changes in Java 11
Rock-paper-scissors in Java
Pi in Java
FizzBuzz in Java
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
Constraint programming in Java
Put java8 in centos7
Combine arrays in Java
"Hello World" in Java
Callable Interface in Java
Comments in Java source
Azure functions in java
Format XML in Java
Simple htmlspecialchars in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Type determination in Java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
Express failure in Java
Create JSON in Java
Date manipulation in Java 8
What's new in Java 8
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java
Initializing HashMap in Java
Try using RocksDB in Java
Read binary files in Java 1
Avoid Yubaba's error in Java
Get EXIF information in Java
Save Java PDF in Excel
[Neta] Sleep Sort in Java
Edit ini in Java: ini4j
Java history in this world
Let Java segfault in 6 lines
Try calling JavaScript in Java
Try developing Spresense in Java (1)
Try functional type in Java! ①
I made roulette in Java.
Create hyperlinks in Java PowerPoint
Implement two-step verification in Java
Refactoring: Make Blackjack in Java
Write flyway callbacks in Java
Topic Analysis (LDA) in Java
Importing Excel data in Java 2
NEologd preprocessing in Java neologdn-java