The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Boxing Conversion in J2SE 5.0
Subject:  Question about the Immutable Objects
Date:  2005-03-25 23:40:06
From:  pdoubleya
Response to: Question about the Immutable Objects


I think this is related to an older, and separate, debate. Objects like Integer and String are immutable, and the question is, does it make sense that the VM instantiates a new Object instance for the value 1, or 100? A clearer example is with Boolean--there can really only be two values for Boolean, and the VM should use the same ones is all cases, all the time.

Caching a range of (common) values is one way to have the VM not have billions of instances of "1" to "127" (pos or negative).

Patrick


 Feed java.net RSS Feeds