Re: public static final - compilation error



On Tue, 28 Jun 2005 17:49:11 +0200, Kamil Roman wrote:

> Hi,
>
> is it possible to initialize a public static final member of a class in
> the class' constructor? I try to do this and I receive error message:
>
> variable PLUS is declared final; cannot be assigned.

{... code ...]

No, the static finals need to be initialized before that. Why don't you
use a static initializer block (static { /* ... */ }), which would be
called at class load, in which you can initialize your members.

--
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"


.



Relevant Pages

  • Re: public static final - compilation error
    ... > is it possible to initialize a public static final member of a class in ... > the class' constructor? ... Prev by Date: ...
    (comp.lang.java.help)
  • Re: Best practice and is there a difference?
    ... classes and not classes where the constructor takes arguments. ... private String string1 = String.Empty; ... I go ahead and initialize them where it is ... In the above case, while I create the list at the member declaration, I ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PATCH 2/3] user.c: use kmem_cache_zalloc()
    ... struct user_struct *new; ... atomic_t contains just a solitary int member, ... that the *zalloc() is assumed to initialize to zero. ...
    (Linux-Kernel)
  • Member Initialization Gotcha!
    ... This only took a few hours to figure out after I finally went back to MSDN and saw this warning regarding member initialization: ... So you would think that two protected const DWORD members shown here would be constructed in its declared order: ... Well, never mind the above uses D1 to initialize D2, the above is drastically reduce code for illustration. ... It showed up when the original constructor: ...
    (microsoft.public.vc.language)
  • Re: Member Initialization Gotcha!
    ... This only took a few hours to figure out after I finally went back to MSDN and saw this warning regarding member initialization: ... So you would think that two protected const DWORD members shown here would be constructed in its declared order: ... Well, never mind the above uses D1 to initialize D2, the above is drastically reduce code for illustration. ...
    (microsoft.public.vc.language)