I have a method which takes an argument Collection
, which could be NULL. I want to end up with a local copy of the input as an ImmutableS
I don't see why you couldn't use Objects.firstNonNull
:
this.foos = ImmutableSet.copyOf(Objects.firstNonNull(foos, ImmutableSet.of()));
You can save some typing with static imports, if that's your thing:
import static com.google.common.collect.ImmutableSet.copyOf;
import static com.google.common.collect.ImmutableSet.of;
// snip...
this.foos = copyOf(Objects.firstNonNull(foos, of()));