Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx11.iad.POSTED!not-for-mail From: Arved Sandstrom User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Autoboxing and Performance ? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 47 Message-ID: X-Complaints-To: abuse@newsgroups-download.com NNTP-Posting-Date: Fri, 30 Aug 2013 00:28:24 UTC Organization: Public Usenet Newsgroup Access Date: Thu, 29 Aug 2013 21:28:23 -0300 X-Received-Bytes: 2350 Xref: csiph.com comp.lang.java.programmer:25173 On 08/20/2013 07:33 AM, Peter Olcott wrote: > On 8/20/2013 5:20 AM, Joerg Meier wrote: >> On Tue, 20 Aug 2013 05:15:30 -0500, Peter Olcott wrote: >> >>> From Java A Beginner's Guide, Fifth Edition by Herbert Schildt, >>> page 425: >> >>> class AutoBox3 { >>> public static void main(String args[]) { >>> Integer iOb; >>> iOb = 99; >> >>> // The following automatically unboxes iOb, >>> // performs the increment, and then reboxes >>> // the result back into iOb >>> ++iOb; >> >>> It seems to me that all this unboxing and reboxing is a complete waste >>> of CPU time. It would make much more sense to provide an >>> Integer.Increment() member function that directly operates on the >>> contained data. >> >>> Why does Java waste so much CPU resources with its unboxing and reboxing >>> in cases such as this, and not simply provide member functions that >>> directly operate on the contained data? >> >> Because IntegerS and other Number classes are immutable. The contained >> data >> is not allowed to be changed under any circumstances. >> >> Liebe Gruesse, >> Joerg >> > > So the original object is replaced with a new object? > > What is the benefit (of immutability) that is worth the cost of this > poor performance? Not being facetious here. Just Google on immutability. AHS -- When a true genius appears, you can know him by this sign: that all the dunces are in a confederacy against him. -- Jonathan Swift