Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail From: =?ISO-8859-1?Q?Sven_K=F6hler?= Newsgroups: comp.lang.java.programmer Subject: Re: Autoboxing and Performance ? Date: Wed, 21 Aug 2013 03:52:07 +0300 Lines: 20 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: news.dfncis.de +Lgtv6k6oSthx9TCU3FqwAdLV6NyPBCZh9rBbIcRAmF1BUlxEn2UXDY6At Cancel-Lock: sha1:Wugk2YbMY3CFMmUqXl3WYaRKBQ0= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130807 Thunderbird/17.0.8 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:25080 Am 20.08.2013 13:33, schrieb Peter Olcott: > What is the benefit (of immutability) that is worth the cost of this > poor performance? Well, if you have a mutable object, programming becomes a bit of a pain, doesn't it? You just checked whether the integer is in a certain range, and asynchronously the value of that variables is changed by another thread. Also, what if you used the Integer object as a key in a hashmap? The hashmap would become inconsistent if the value of that Integer object changes. That said, I seriously think that all the wrapper classes were just intended for what the name suggests: wrapping a primitive type when you really need an Object. And most of the time you don't need an object. I'd even call program is seriously broken if it uses Integer where int could be used. I was never in need of a mutable Integer. Regards, Sven