Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Usefulness of "final" (Was: Re: Inserting In a List) Date: Thu, 04 Apr 2013 19:50:12 +0200 Lines: 42 Message-ID: References: <19un43xj77bua.vw45l4e2wshi.dlg@40tude.net> <515cabb2$0$32111$14726298@news.sunsite.dk> <515cc192$0$32109$14726298@news.sunsite.dk> <515cc46b$0$32111$14726298@news.sunsite.dk> <515cc8e5$0$32109$14726298@news.sunsite.dk> <7fdeb9cc-d961-44b1-abfd-5ffb03715058@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net TnZ3tLfi/Fn9DvzlpOkv/AqqGX5r9jc3sxUVCrCWh8ExdHJHM= Cancel-Lock: sha1:08Q3Mh/zRjRxkQmWzn6zg9Gz3xs= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 In-Reply-To: X-Antivirus: avast! (VPS 130404-0, 04.04.2013), Outbound message X-Antivirus-Status: Clean Xref: csiph.com comp.lang.java.programmer:23309 On 04.04.2013 06:30, markspace wrote: > On 4/3/2013 8:45 PM, Lew wrote: >> markspace wrote: >>> Eric Sosman wrote: >> Section 17.5, however, does define "thread-safe immutable": > ... >> The word "immutable" is apparently to be understood in its common >> computer-science meaning. > > Section 17.5 says this in its second paragraph: > > "final fields must be used correctly to provide a guarantee of > immutability." > > That's the last sentence. To me that's ascribing special semantics to > just the word 'immutable.' If it's saying "final fields must be used" > then it's special for final fields. I realize there a qualifier on > that, but the qualifier is "correctly" and they're just pointing out > it's a little tricky. final fields must be used is the key point. > (Used incorrectly, of course, they won't guarantee immutability.) The sentence states that you will only get immutability if you use final fields correctly. That does not imply that final fields are necessary to achieve immutability. For at least one definition of "immutable" you can create classes with no setters and getters only returning immutable objects - without ever using the keyword "final". > I see how you might read that differently, but without final fields the > number of useful immutable classes is pretty small. (I'm ignoring > stateless objects here.) Not at all. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/