I feel like there must be a better way to handle getting and processing, but I’m not seeing anything.
My code is littered with null checks immediately before “doing the thing”
Map<Integer, Animal> zoo = new HashMap();
..... Fill zoo .....
Animal a = zoo.get(id);
if(a != null) {
a.feed(food);
}
Is there some way to better process this? Such as
zoo.getAndUse(id, animal -> animal.feed(food));