Answers for "java coalesce"

0

java coalesce

// Short answer: no

// The best you can do is to create a static utility method (so that it can be 
// imported using import static syntax)

public static <T> T coalesce(T one, T two)
{
    return one != null ? one : two;
}

// The above is equivalent to Guava's method firstNonNull by @ColinD, but that 
// can be extended more in general

public static <T> T coalesce(T... params)
{
    for (T param : params)
        if (param != null)
            return param;
    return null;
}
Posted by: Guest on December-01-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language