For Programmers: Free Programming Magazines  


Home > Archive > Java Help > August 2005 > Re: public static final - compilation error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: public static final - compilation error
Roedy Green

2005-08-29, 3:57 am

On Tue, 28 Jun 2005 17:59:12 +0200, Thomas Fritsch
<i.dont.like.spam@invalid.com> 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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com