public List foo1() {
List retval = bar();
if (retval == null)
return Collections.emptyList();
else
return ret
Compiles for me fine in java 8.
Earlier versions of Java might need more help
return retval == null ? Collections.<String>emptyList() : retval;
should work.
EDIT This is due to improvements in Java 8 type inference as explained here
http://openjdk.java.net/jeps/101
And here's a blog with the highlights: http://blog.jooq.org/2013/11/25/a-lesser-known-java-8-feature-generalized-target-type-inference/
This is related with Type Inference from a generic method.
In case of code before ver. 8. It must be declared the type of result for this case.
return retval == null ? Collections.<String>emptyList() : retval;
Since ver. 8 notion of what is a target type has been expanded to include method arguments. So this is no longer required.