coalesce java code example
Example: 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;
}