Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.netfront.net!not-for-mail From: Wanja Gayk Newsgroups: comp.lang.java.programmer Subject: Re: Usefulness of "final" (Was: Re: Inserting In a List) Date: Sat, 6 Apr 2013 21:58:33 +0200 Organization: Netfront http://www.netfront.net/ Lines: 56 Message-ID: References: <19un43xj77bua.vw45l4e2wshi.dlg@40tude.net> <515cabb2$0$32111$14726298@news.sunsite.dk> <515cc192$0$32109$14726298@news.sunsite.dk> <515cc3b2$0$32111$14726298@news.sunsite.dk> <515cde06$0$32111$14726298@news.sunsite.dk> NNTP-Posting-Host: 77.8.248.100 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 8bit X-Trace: adenine.netfront.net 1365278166 84137 77.8.248.100 (6 Apr 2013 19:56:06 GMT) X-Complaints-To: news@netfront.net NNTP-Posting-Date: Sat, 6 Apr 2013 19:56:06 +0000 (UTC) User-Agent: MicroPlanet-Gravity/3.0.4 Xref: csiph.com comp.lang.java.programmer:23354 In article <515cde06$0$32111$14726298@news.sunsite.dk>, Arne Vajhøj (arne@vajhoej.dk) says... > > On 4/3/2013 9:37 PM, markspace wrote: > > On 4/3/2013 6:25 PM, Eric Sosman wrote: > > > >> On 4/3/2013 8:24 PM, markspace wrote: > >>> final is necessary. [...] > > > >> > >> public class Immutable { > >> private int value; > >> public Immutable(int value) { > >> this.value = value; > >> } > >> public int getValue() { > >> return value; > >> } > >> } > >> > >> Claim: Immutable is immutable, despite the lack of "final". > >> > > > > Not in the sense of section 17.5 of the JLS, which is what I linked to > > above (and also uses the term "thread safe immutable" to describe the > > semantics of final fields). > > The point of final for thread safeness is well known. Mark, I think you have read "Java concurrency in practice", you should know better. "final" is not necessary to get a thread safe immutable object either, there is the "volatile" keyword to get the memory model right and there are synchronized blocks. What are we talking about here anyway? The "final" keyword is very helpful to create a thread safe and immutable class, but it is neither necessary, nor is its usage giving you any guarantee of immutability, period. And before you start arguing about the "final class XY" definition, just remember visibility contraints and factories. This argment is getting pretty useless. Kind regadrs, Wanja -- ..Alesi's problem was that the back of the car was jumping up and down dangerously - and I can assure you from having been teammate to Jean Alesi and knowing what kind of cars that he can pull up with, when Jean Alesi says that a car is dangerous - it is. [Jonathan Palmer] --- news://freenews.netfront.net/ - complaints: news@netfront.net ---