X-Received: by 10.224.110.68 with SMTP id m4mr2919174qap.2.1365065744101; Thu, 04 Apr 2013 01:55:44 -0700 (PDT) X-Received: by 10.49.6.66 with SMTP id y2mr497173qey.18.1365065744087; Thu, 04 Apr 2013 01:55:44 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!t2no38299580qal.0!news-out.google.com!ef9ni1849qab.0!nntp.google.com!ca1no28743343qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Thu, 4 Apr 2013 01:55:43 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=81.94.213.9; posting-account=VsWLXwoAAAB13M2Ptt5-Bo-K_zCx-zyw NNTP-Posting-Host: 81.94.213.9 References: <19un43xj77bua.vw45l4e2wshi.dlg@40tude.net> <515cabb2$0$32111$14726298@news.sunsite.dk> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Usefulness of "final" From: paul.cager@gmail.com Injection-Date: Thu, 04 Apr 2013 08:55:44 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.java.programmer:23284 On Thursday, 4 April 2013 06:42:34 UTC+1, Leif Roar Moldskred wrote: > markspace wrote: > > > > ... Are you trying to tell me that final fields are > > not involved in immutability in Java? > > For what it's worth, they're not: > > public class ThisIsImmutable { > private String cantChangeMe; > public ThisIsImmutable(String value) { > this.cantChangeMe = value; > } > public String getCantChangeMe() { > return this.cantChangeMe; > } > } Interestingly, is "ThisIsImmutable" immutable given you can do this? public class NowItIsnt extends ThisIsImmutable { public String getCantChangeMe() { return Integer.toString(new Random().nextInt()); } } Of course you could make ThisIsImmutable final.