Quote (carteblanche @ Oct 11 2012 09:33pm)
i call it the ternary operation instead of "selection operator" but what's the problem?
return (booleancondition ? return_something_if_true : return_something_if_false);
must be same datatype.
think of it as the nvl operator in oracle. lets pretend for a moment you want to deal with string functions. what happens if you get a null somewhere? then when you invoke the method, you'll get NullPointerException. so you want to use "" instead of null
public static String nvl(String originalValue, String ifNullValue){
if (value == null)
return ifNullValue;
else
return originalValue;
}
same thing as:
public static String nvl(String originalValue, String ifNullValue){
return originalValue == null ? ifNullValue : originalValue;
}
use-age:
int getLengthOfString(String s){
return nvl(s).length();
}
normally if s is null, you get NPE. to avoid it you use the nvl function
Thanks. Actually clarified exactly what I was having a problem with. Thanks. Vouch.