Something I do sometimes in code is "If this list is null, replace it with an empty list." This code is simple but I do it often enough that I wonder if apache or google already has something in their standard library that solves this problem.
Asked
Active
Viewed 315 times
2
-
1I suggest you look into using the new [`Optional`](http://docs.oracle.com/javase/8/docs/api/java/util/Optional.html) type in Java 8. If you aren't using Java 8, [Guava `Optional`](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Optional.html) is an alternative. – Elliott Frisch Jan 20 '15 at 17:41
-
1Google does not offer it because they believe objects of list types should never be `null` in the first place. Which is completely true, although it overlooks code that may be generated or libraries you call. – Ingo Bürk Jan 20 '15 at 17:51
-
Related: http://stackoverflow.com/questions/6910002/google-guava-isnullorempty-for-collections?lq=1 – Louis Wasserman Jan 20 '15 at 17:58