0

The issue of using or not using the Java final keyword has been discussed many times on SO. I am trying to collect some well-known open source Java projects that are using it. I haven't found any so far. Can you tell me some?

Questions about using or not using final:

Why would one mark local variables and method parameters as "final" in Java?

Using "final" modifier whenever applicable in java

Why are local variables not declared final in most open source java projects?

Community
  • 1
  • 1
jabal
  • 11,987
  • 12
  • 51
  • 99
  • To clarify what I meant by "everywhere" see the first question link. – jabal Mar 13 '12 at 09:19
  • 1
    For this case it looks like search engines including Google Web Search, Koders, Krugle, and JExamples are "pessimized" (that is, optimized for other cases causing imprecise results for this case). – minopret Mar 13 '12 at 09:39
  • This question is not a good fit to our Q&A format. We expect answers to generally involve facts, references, or specific expertise; this question will likely solicit opinion, debate, arguments, polling, or extended discussion. – oers Mar 13 '12 at 09:59
  • Sorry if I misunderstood the policy, however I think I did not ask opinions. Enumerating project names is an objective thing. – jabal Mar 13 '12 at 10:12
  • This question would help me to make a decision in a greenfield project. I think collecting industry examples could help not only me, but others as well. – jabal Mar 13 '12 at 10:15
  • You may be right, but your question is not in scope for this Question and Answer site. Please have a look at the [FAQ](http://stackoverflow.com/faq#dontask) – oers Mar 13 '12 at 11:20

3 Answers3

2

I know opengamma sometimes use final parameters / variables, although it does not seem to be a strict rule. I'd say they probably use final less than 5% of the time. See for example this sample, lines 192-193, 215.

assylias
  • 321,522
  • 82
  • 660
  • 783
  • 1
    The old OpenGamma coding guidelines required `final` on all local variables and parameters, but wasn't always followed. The new OpenGamma coding guidelines for Java 8 recommend against using `final` (due to effective final concept in Java8). See Strata - https://github.com/OpenGamma/Strata – JodaStephen Oct 10 '16 at 10:01
2

Here are some projects that use final parameters and locals. They are not selected for prominence or activity. I'm not sure how I would do that.

I gathered them from Google: allintext: "final" import site:sourceforge.net

  • wnpojo.sf.net wraps WordNet entities in Java classes
  • spnego.sf.net integrates Windows authentication in Java
  • waterken.sf.net provides asynchronous invocation over HTTP
  • jeuclid.sf.net renders MathML
  • statcvs.sf.net describes CVS projects as tables and charts

Here are some highly prominent projects that do not (at least, not in the files that I inspected) use final parameters and locals in their Java code.

  • GNU: GNU Classpath
  • Samba: JCIFS
  • MySQL: Connector/J
  • ANTLR
  • Amazon Web Services (AWS) Toolkit for Eclipse
  • Apache Tomcat
  • Bouncy Castle
  • Eclipse: Java Developer Toolkit (JDT), core UI
  • Google Web Toolkit (GWT): Mobile WebKit
  • International Components for Unicode for Java (ICU4J)
  • JUnit
  • OpenJDK
  • Spring: Spring Framework
minopret
  • 4,726
  • 21
  • 34
0

check Guava libraries - sample

Premraj
  • 7,802
  • 8
  • 45
  • 66
  • well, I checked out the code, but it seems to me that they do not really use it strictly. http://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/math/MathPreconditions.java – jabal Mar 13 '12 at 09:11
  • In your link I didn't see any state which can be marked final, if you are referring to method parameters, well I guess there is no need :) – Premraj Mar 13 '12 at 09:17
  • Putting it into every method signature if possible for example. The sample link you sent shows some methods that use it this way, but did not convince me that Guava is a good example. – jabal Mar 13 '12 at 09:18
  • Whats the need to put final on each method variable? – Premraj Mar 13 '12 at 09:29
  • @jabal see [this](http://stackoverflow.com/questions/266806/is-there-any-performance-reason-to-declare-method-parameters-final-in-java#266981) – Premraj Mar 13 '12 at 09:45