Use Constraints
:
import com.google.common.collect.Constraints;
...
Constraints.constrainedList(new ArrayList(), Constraints.notNull())
from Guava for maximum flexibility.
UPDATE: Guava Constraints has been deprecated in Release 15 – apparently without replacement.
UPDATE 2: As of now (Guava 19.0-rc2) Constrains is still there and not deprecated anymore. However, it’s missing from the Javadoc.
I’m afraid that the Javadoc is right as MapConstraint
have been deprecated in Release 19, too