Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Usefulness of "final" (Was: Re: Inserting In a List) Date: Tue, 02 Apr 2013 16:41:00 -0400 Organization: A noiseless patient Spider Lines: 40 Message-ID: References: <19un43xj77bua.vw45l4e2wshi.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 2 Apr 2013 20:38:42 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="0d73d8cc209bff1c6395088b400d0605"; logging-data="2575"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187XIPoI4Cr4UKnUBM4cTcf" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 In-Reply-To: Cancel-Lock: sha1:1VjlSLqlGZ5ogvxhu4jqb0UoJGw= Xref: csiph.com comp.lang.java.programmer:23192 On 4/2/2013 3:06 PM, Robert Klemme wrote: >[...] > 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. [...] De gustibus non disputandum est, but I think "final" should be reserved for things that *mustn't* change, and shouldn't just be pasted on to anything that happens to remain constant in the code's current incarnation. When considering a change to some code I might see Thing thing = getThing(); // ... code that doesn't happen to change `thing' or I might see final Thing thing = getThing(); // ... code that (obviously) doesn't change `thing' In the first case I might think about inserting, say, if (thing == null) thing = fallbackThing(); ... while in the second case I wouldn't even consider it: I would suppose that the code relied on `thing' being exactly what getThing() had returned, perhaps in some way and for some reason not clear to me. But, as I said above, de gustibus. > Generally I find "finally" quite useful - apparently significantly more > useful than you do. :-) "finally" is a Godsend -- but did you mean "final"? -- Eric Sosman esosman@comcast-dot-net.invalid