Original issue created by hoodwgs on 2010-07-20 at 07:31 PM
It would be nice to have an varargs Objects.firstNonNull()
This would reduce a lot of "if"s "else"s.
Implementation:
public static <T> T firstNonNull( T... objs ){
for( T obj : objs )
if( obj != null )
return obj;
throw new NullPointerException();
}
Utilization:
String var1 = null;
String var2 = null;
String var3 = "ccc";
String var4 = "aaa";
String aaa = Objects2.firstNonNull( var1,var2,var3,var4 );
System.out.println( aaa );
Maybe we can put some similar methods on the GUAVA
like...
Iterable.firstNonNull( Iterable<T> col )
Original issue created by hoodwgs on 2010-07-20 at 07:31 PM
It would be nice to have an varargs Objects.firstNonNull()
This would reduce a lot of "if"s "else"s.
Implementation:
public static <T> T firstNonNull( T... objs ){
for( T obj : objs )
if( obj != null )
return obj;
throw new NullPointerException();
}
Utilization:
String var1 = null;
String var2 = null;
String var3 = "ccc";
String var4 = "aaa";
Maybe we can put some similar methods on the GUAVA
like...
Iterable.firstNonNull( Iterable<T> col )