Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #449 > unrolled thread

Re: static final int, but constructor with (final int) arguments

Started by"Alex Mentis" <foo@invalid.invalid>
First post2011-03-29 16:03 +0000
Last post2011-03-29 16:03 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.java.help

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: static final int, but constructor with (final int) arguments "Alex Mentis" <foo@invalid.invalid> - 2011-03-29 16:03 +0000

#449 — Re: static final int, but constructor with (final int) arguments

From"Alex Mentis" <foo@invalid.invalid>
Date2011-03-29 16:03 +0000
SubjectRe: static final int, but constructor with (final int) arguments
Message-ID<imsvsu$n48$1@dont-email.me>
Lew wrote:

> Alex Mentis wrote:
> > You don't really need to make it final. Since c is declared private,
> > the only way that c's value could change is if you write a method
> > that assigns a new value to c. As long as you don't do that (and you
> 
> Ah, there's the magic wand.
> 
> "As long as you don't do that ...".
> 
> 'final' engages the compiler's support to make sure that you don't.
> 
> And there are semantics relating to initialization order and
> multi-threaded access where 'final' makes a significant difference.
> 
> > shouldn't need to, if c is not supposed to change), the only way c's
> > value will ever change is when the object is first created and the
> > contructor sets it to whatever value c should have for the object's
> > lifetime.
> 
> If this is the scenario, then you really should lock it down with
> 'final'.

Yes, you're absolutely right. Both you and rossum provided the best
solution (use final instead of static final). My response was subpar at
best, and it would actually be fair to go as far as calling it "wrong"
- especially in this case.

[toc] | [standalone]


Back to top | Article view | comp.lang.java.help


csiph-web