Re: JavaMemoryModel: final isn't used much in the JDK, even when it could

From: Paul Haahr (haahr@jivetech.com)
Date: Wed Jul 21 1999 - 12:11:13 EDT


> Does anyone have a feel for why final is used so rarely? It certainly
> seems like it could be used much more. It might be very useful
> to a compiler to know that the field is final (then you can know
> that it won't be modified by a method call).

Language changes and compiler bugs?

Until 1.1, when inner classes were added to the language, ``blank final
instance variables'' (that is, final fields which are initializated in
constructors or non-static initializers, rather than an initialization
expression in the declaration) were not part of Java, the language,
despite the fact that they were acceptable to VMs.

Then, even when it became part of the language, there are all sorts of
problems with the 1.1 vintage javac that prevent use of final for many
fields which are treated as final. (If I remember correctly, one example
in the 1.1 JDK is that a final field initialized by all constructors is
still reported as ``not initialized'' if its class has an inner class.)

Thus, program authors have had only limited time and limited opportunity
to make many nominally final fields actually final.

--p
-------------------------------
This is the JavaMemoryModel mailing list, managed by Majordomo 1.94.4.

To send a message to the list, email JavaMemoryModel@cs.umd.edu
To send a request to the list, email majordomo@cs.umd.edu and put
your request in the body of the message (use the request "help" for help).
For more information, visit http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:17 EDT