Say I have the following code:
Map<String, Boolean> map = ...
map.put("foo", true);
Theoretically, true
will have to be autoboxed, resulting in a slight performance hit versus inserting Boolean.TRUE
. But since we're dealing with a literal value, is it possible for the compiler to replace the primitive literal with a boxed literal so there's no extra runtime overhead?
Before anyone attacks me, I would generally opt for the primitive literal for the sake of code clarity, even if there was a tiny performance cost. This question is mostly theoretical.
map.put
– SqueakBoolean
constant;map.put("foo", Boolean.TRUE);
– Orientalismtrue
withTRUE
. – Hypodermis