Java null coalescing operator

I'm thinking it's not cool because Java doesn't have a null coalescing operator As soon as the Util function is prepared

I wonder if it can be used with the name coalesce as if it were a SQL function.

public final class Utils {
    @SafeVarargs
    public static <T> T coalesce(T... value) {
        for (T v : value) {
            if (v != null) {
                return v;
            }
        }
        return null;
    }
}
    public static void main() {
        String foo = null;
        String bar = null;
        String hoge = Utils.coalesce(foo, bar, "huga");
        System.out.println(hoge);
    }

But to be honest, I want to use a ?? operator like C #.

Recommended Posts

Java null coalescing operator
JAVA NULL checker
Study Java # 2 (\ mark and operator)
[Java] Summary of operators (operator)
Java learning memo (logical operator)
Java basic learning content 3 (operator / ternary operator)
[Java beginner] == operator and equals method
Java
Java
[Java] Convert Object type null to String type
Kotlin's Null safety to send to Java developers