On Sun, 23 Jan 2005 16:06:42 -0600, Eddie Bush <[EMAIL PROTECTED]> wrote:

> Not to start another holy war, but perhaps you all could help me
> either solidify or dispell something I learned ...
> 
> I've always been of the impression that mentioning a value for a
> startic final member is poor form, and that this should always be done
> in a static intializer, thus:
> 
> public class Foo {
>   public static final String bar;
> 
>   static {
>     bar = "baz";
>   }
> }
> 
> My understanding is that, having called "bar" static final, it will be
> inlined and cause things that use Foo to have a compile dependency on
> Foo.  To clarify, if you build something against Foo, and Foo changes
> (bar is now equal to "fee", and not "baz"), you would have to rebuild
> for your code to notice the change.  Doing things as per above, as I
> understand it, keeps this from happening and removes the compile
> dependency.

The approach you describe above (with a separate static initializer)
is functionally equivalent to the following:

> public class Foo {
>   public static final String bar = "baz";
> }

Which, in essence, creates a static initializer for you.  The ability
to inline the constant in other classes is a feature of the "final"
declaration, now how the variable's value is initialized.

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to