Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #454
| From | Lew <noone@lewscanon.com> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: static final int, but constructor with (final int) arguments |
| Date | 2011-03-29 19:03 -0400 |
| Organization | albasani.net |
| Message-ID | <imtofi$q0t$1@news.albasani.net> (permalink) |
| References | <87sju7w4o5.fsf@merciadriluca-station.MERCIADRILUCA> <878vvzlzeo.fsf@merciadriluca-station.MERCIADRILUCA> <imrs3r$lpn$1@news.albasani.net> <87bp0tv945.fsf@merciadriluca-station.MERCIADRILUCA> |
Merciadri Luca wrote: > Lew writes: >> The finality of parameters is completely unrelated. ... >>> I'm here in the case where each instance of my class defines an object >>> whose c is the same (-> static), where c is a constant (-> final), and >>> which does not need to be accessed from other classes (-> private). [Lew:] >> What do you mean by "is the same"? You left out the same as what. >> What is it the same as? [Merciadri:] > Every new ClassName() creates an object so that its c is the > same. This is normal as there is only one c variable in memory, as it > is static. Yes. If it is 'static final' (keyword order is reversible) then that one value is fixed before any class instance can be created. ... > So, is there any reason in the context of my program to declare the > three ints coming from the CLI (once exactly) as final or not? Their Well, you're only declaring individual variables 'final' or not. You can assign a value from a 'final' to a non-'final' and vice versa. In your case, you wonder if the specific method or constructor arguments should be 'final'. That has no influence on anything else done with the data from the CLI. You can corrupt the heck out of data using 'final' variables if you like. > value do not change, and they are only defined once: the user makes > java myProgram 1 2 3, and then each argument is kept in some > variable. I consider that this variable should be static, as the user > is never invited to type any other stuff in the CLI. No, the variable should not be static. The decision is not connected to whether the user ever receives any invitations. The decision is whether it represents state of an instance or the whole class. In your case, if you have an instance of some class managing the interaction with the user, as you should, then the variable receiving the data should be neither static nor instance, in other words, not a member at all, but a local variable. If you need to keep the data in something to move it around to helper methods, then you encapsulate it in an instance of some class. That means for that helper class, the data will be kept in instance state. Not class state, instance state. Thus in the helper class, the data should be in instance variables. Most of the time, those should be 'final' instance variables. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: static final int, but constructor with (final int) arguments Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-03-30 00:45 +0200
Re: static final int, but constructor with (final int) arguments Lew <noone@lewscanon.com> - 2011-03-29 19:03 -0400
Re: static final int, but constructor with (final int) arguments Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-03-30 19:05 +0200
[OT] Re: static final int, but constructor with (final int) arguments Stanimir Stamenkov <s7an10@netscape.net> - 2011-03-30 08:24 +0300
Re: [OT] Re: static final int, but constructor with (final int) arguments Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-03-30 19:05 +0200
csiph-web