Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Wrapper Classes do not have pool Similar to Stringpool?

Integer, Character, Double, etc. -- all these are immutable classes like String. String has Stringpool to save memory but why don't these wrappers have similar pools?

I have checked: Integer has a similar pool only up to 127, but not more than that.

like image 997
Shayan Ghosh Avatar asked Jun 10 '26 06:06

Shayan Ghosh


1 Answers

Unless someone can find a design document from Gosling, et. al., circa 1994 or so that specifically addresses this, it's impossible to say for certain.

One likely reason is that the complexity and overhead weren't deemed worth the benefit. Strings are A) a lot bigger and B) a lot more common than Integer, Long, and such, as mostly people use primitives whenever they can, only using the wrappers where they can't avoid it.

like image 133
T.J. Crowder Avatar answered Jun 15 '26 21:06

T.J. Crowder