Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #java #coalesce
ADD COMMENT
Topic
Name
2+6 =