What is the best way to guard against null in a for loop in Java?
This seems ugly :
if (someList != null) { for (Object object : someList) {
With Java 8 Optional:
Optional
for (Object object : Optional.ofNullable(someList).orElse(Collections.emptyList())) { // do whatever }