In Java, this works:
String foo = a();
if(foo == null){
foo = b();
}
if(foo != null){
list1.add(foo);
}
However, its ugly to look at because it looks like it should be handled as an if/else, even though it cannot be. Is there a neat way to handle checking if a variable is STILL null after possibly setting it to a non-null value?
You have two options:
1) Optional class
2) Chain of Responsibility pattern for fallbacks