I have a function that combines a set of lines like this:
StringBuffer sb = new StringBuffer();
sb.append(fct1());
sb.append(fct2());
sb.append(fct3());
Where fct1 (), fct2 () and fct3 () should return String. The problem is that I have to check the return values as follows:
sb.append(fct1() == null ? "" : fct1());
because I get an exception if the value is null.
The problem is that I have a lot of instructions like this, and above all, I cannot change these functions that return strings (fct1, fct2 and fct3).
Is there a solution that will automatically "clear" my lines?
Thank.
PS: I created a function that can do this:
public String testNullity(String aString){
aString == null ? "" : aString;
}
so that I can call it like this:
sb.append(testNullity(fct1));
sb.append(testNullity(fct2));
...
source
share