I think that I'd prefer the if statements. Under the hood of whatever language you use, this is a more expensive operation, and things can go wrong if the map is messed with.
Just as a clarification, this map returns a immutable map, so you can’t really mess with it after it’s initialized.
As for the expensiveness, I don’t know if the Java compiler could do some kind of optimization for example.
Either way unless it’s a critical performance feature I prefer to optimize code for readability over what I think would be really small performance benefits.
Thanks for replying!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think that I'd prefer the if statements. Under the hood of whatever language you use, this is a more expensive operation, and things can go wrong if the map is messed with.
Hi Grim,
Just as a clarification, this map returns a immutable map, so you can’t really mess with it after it’s initialized.
As for the expensiveness, I don’t know if the Java compiler could do some kind of optimization for example.
Either way unless it’s a critical performance feature I prefer to optimize code for readability over what I think would be really small performance benefits.
Thanks for replying!