B
blue indigo
blue said:Mark Thornton wrote:
Boxing of primitives costs memory too. The ability to eliminate the
boxing involved in Integer[] vs int[] is still a long way off (and may
require a change in the language so that
new Integer.valueOf(x) == Integer.valueOf(x) for all x).
You mean "so that mew Integer(x) == Integer.valueOf(x) for all x", do
you not?
You mean "so that new Integer(x) == Integer.valueOf(x) for all x", do
you not?
No, because outside a small range Integer.valueOf(x) is implements as
new Integer(x).
Eh -- I was correcting the spelling. What are you suggesting, just that
Integer.valueOf(x) == Integer.valueOf(x)? That's much more workable as it
doesn't mess with the semantics of new.
This is just too expensive.
Not if it's implemented smart, by making the Integer object an "int with
methods" rather than really a reference type. It's immutable so it won't
alter program semantics. The only slightly-tricky bit is locking. If an
instance is ever synchronized, some proxy object has to be locked, and it
must be associated with the integer value in a hashmap somewhere. This can
be lazily created the first time the value is synchronized on. Then the
tricky bit becomes cleaning deadwood out of the same hashmap, as even
using a weak hash map the integer key would not get collected. But
unlocking the integer can remove the mapping if the lock count just went
to zero.