// If you need to force the object not to be null Objects.requireNonNull( whatever ) // i.e public void add(Animal animal) { Objects.requireNonNull(animal) zoo.add(animal); }