I have a method which takes an argument Collection foos, which could be NULL. I want to end up with a local copy of the input as an ImmutableS
Collection foos
ImmutableS
A Collection is a reference like any other, so you could do:
Collection
ImmutableSet.copyOf(Optional.fromNullable(foos).or(ImmutableSet.of()));
But that is becoming quite a handful to write. More simple:
foos == null ? ImmutableSet.of() : ImmutableSet.copyOf(foos);