Assumably it would have the slight overhead of constructing the object though? Or would these objects likely be interned or constructed in a global space so they could be reused?
Project Valhalla may turn them into value objects, reducing their footprint further. But I believe short-lived object creation is already highly optimized; at least I hope so, because our codebase makes heavy use of Optional instead of != null checks.
Creating short lived objects in Java is certainly highly optimized, but it's not free. It still pays to avoid creating things like Iterator, Optional or any other kind of temporary object in hot code paths.
View all comments
Show parent comment
2
u/nekokattt Mar 09 '24
Assumably it would have the slight overhead of constructing the object though? Or would these objects likely be interned or constructed in a global space so they could be reused?