Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Generics and downcasts Date: Tue, 25 Apr 2017 19:54:31 -0400 Organization: Aioe.org NNTP Server Lines: 27 Message-ID: References: <90e70a8b-5e6d-45cc-a42d-976b2dec543e@googlegroups.com> NNTP-Posting-Host: PBuS014lhzVyHjLbXmo/ZQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:36536 On 4/25/2017 4:35 PM, Eric Douglas wrote: > On Tuesday, April 25, 2017 at 4:21:08 PM UTC-4, Arne Vajhøj wrote: >> Like many myths about Java performance, the erroneous >> belief that declaring classes or methods as final results in better >> performance is widely held but rarely examined. The argument goes >> that declaring a method or class as final means that the compiler >> can inline method calls more aggressively, because it knows that at >> run time this is definitely the version of the method that's going >> to be called. But this is simply not true. Just because class X is >> compiled against final class Y doesn't mean that the same version >> of class Y will be loaded at run time. So the compiler cannot >> inline such cross-class method calls safely, final or not. Only if >> a method is private can the compiler inline it freely, and in that >> case, the final keyword would be redundant. > > Eclipse Cleanup adds final modifiers all over the place. I don't > recall if these are supposed to help performance. All I know is 3 of > the purposes for final. 1) declaring a public, usually static > constant variable 2) declaring a class that should never be extended > and 3) declaring a variable in a class that needs to pass directly > into something, like a SwingWorker. There are reasons to use final. Just not performance optimization. Arne