Re: public static final - compilation error



On Tue, 28 Jun 2005 17:59:12 +0200, Thomas Fritsch
<i.dont.like.spam@xxxxxxxxxxx> wrote or quoted :

>No, you can't initialize 'static final' things in a constructor or any
>non-static method. But you can (and probably want to) initialize them in
>the class initializer:

The reason is a constructor will be called many times, at least
potentially, but a static initialiser block is guaranteed to be called
exactly once.

Java does not want to deal with the possibility of you changing your
mind about a final value.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
.



Relevant Pages

  • Re: Inherited Methods and such
    ... what I see in Initialize is ... Now, what you want is to get in the constructor of some S derived from T, ... The base types and registry are part of the framework and the user ... provides the concrete factories. ...
    (comp.lang.ada)
  • Re: Strange member pointer error - even the debugger is confused.
    ... Initialize m_pHead in your constructor to NULL. ... "Aaron Lawrence" wrote in message ... > class ATL_NO_VTABLE CIfsf: ...
    (microsoft.public.vc.language)
  • Re: Initialization & Inheritance
    ... for a recent project I was trying to initialize members of a derived ... class from the constructor of the super class (done using an abstract ... initialize, but double initialization. ... if you used the pointer as it stood, ...
    (comp.lang.java.programmer)
  • Re: Initializing static readonly methods
    ... public class TestClass ... //So assigning a value to readonly is perfectly fine. ... //readonly values are has to be initialized in constructor. ... There is no other place to initialize them. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: initialising properties in static constructor
    ... When static constructor is static it cannot initialize instance variables ... To intialize them in the constructor. ...
    (microsoft.public.dotnet.languages.csharp)