Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 03 Apr 2013 05:15:49 -0500 Date: Wed, 03 Apr 2013 11:15:47 +0100 From: lipska the kat <"nospam at neversurrender dot co dot uk"> Organization: Trollbusters 3 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Usefulness of "final" (Was: Re: Inserting In a List) References: <19un43xj77bua.vw45l4e2wshi.dlg@40tude.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 57 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-hiFUzqj2BexUaSSfzQoUcplbaW3dc2lq+2nAqZC9HbSTkT0x+KtSjeuvi7nVVzuSHDpvLNPAllAeAu/!J+ibgWyaaLes8/tVqgD2IJ3SQ75JwZRWosEGPvMmYZAwQ08F/kJLjriWmsqmOuHOC0H2FLwyu44= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3147 Xref: csiph.com comp.lang.java.programmer:23216 On 02/04/13 20:06, Robert Klemme wrote: > On 04/02/2013 04:08 PM, lipska the kat wrote: > >> Just as a matter of interest what's with all the finals >> >> particularly >> >> for (final File name : folder.listFiles()) [snip] > I believe in using "final" pretty often as it will immediately indicate > which local variables are constant for a method call and which are > modified all the time. Plus, with "final" you can easier catch errors > in control flow: > > final String x; > > if ( someCondition() ) { > x = y.toString(); > } > else { > if ( someOtherCondition() ) { > x = "foo"; > } > // forgot the else branch here > x = "bar"; > } > > System.out.println("We got " + x); > > Generally I find "finally" quite useful - apparently significantly more > useful than you do. :-) Well I'm not sure that using a storage class to help you write a conditional statement is 'good programming style' but hey ho, different strokes for different folks :-) I know you mean final of course. finally is the last recourse of the desperate :-) Anyway, the usability of final depends on your point of view I suppose. If for some reason I find myself using 'final' all over the place then I would have to ask myself if my abstraction was coherent. If one has something, or in fact a number of somethings that need 'protecting' in this way then surely it is better to wrap them up in a component and control access by virtue of the public interface of that component. It's more OO, makes for cleaner code and of course provides opportunity for the holy grail of OO 're-usability' lipska -- Lipska the KatŠ: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun