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


Groups > comp.lang.java.help > #1572

Re: Global enums and constants

From Arved Sandstrom <asandstrom3minus1@eastlink.ca>
Newsgroups comp.lang.java.help
Subject Re: Global enums and constants
References (2 earlier) <ddd2aaca-22b4-49e5-8d18-96a2c0175fa6@f30g2000yqh.googlegroups.com> <W5R_q.21136$4K5.16082@newsfe16.iad> <10392490.302.1329327531503.JavaMail.geo-discussion-forums@pbcwl10> <vidoj7pntf347tqvcg31ug89kbesikt9bv@4ax.com> <31111629.159.1329352095952.JavaMail.geo-discussion-forums@pbcqw3>
Message-ID <T_Y_q.2$MK6.1@newsfe19.iad> (permalink)
Organization Public Usenet Newsgroup Access
Date 2012-02-15 21:30 -0400

Show all headers | View raw


On 12-02-15 08:28 PM, Lew wrote:
> Roedy Green wrote:
>> Lew wrote, quoted or indirectly quoted someone who said :
>>> Being 'static' is not part of the definition of a Java constant variable.
>>> "We call a variable, of primitive type or type String, that is final and=20
>>> initialized with a compile-time constant expression (=A715.28) a constant=
>>> =20
>>> variable."
>>
>> Constant in Java land just means not-changing once defined.  In
> 
> One must be careful not to entangle the common use of the term "constant" in 
> this sense from the formal definition in Java.
[ SNIP ]

Roedy's definition is OK, assuming "not-changing once defined"
identically means "can't be changed". The actual definition of "constant
variable" in JLS 4.12.4, the one that you quoted, is the only definition
that makes sense with Roedy's simplified language. After all, what's the
point in saying that some variable is a constant because even though it
could be changed, it's documented someplace that you shouldn't and
everyone has promised not to?

I can't think of a sensible common use of the term "constant" in Roedy's
sense that doesn't equate to the actual formal JLS definition. I'm also
a bit surprised to hear that many Java programmers may think of
immutables as constants; that's thinking at cross-purposes, because
constants are constant _variables_. Objects themselves, immutable though
they might be, are not constants, because they are not variables.

As a sidenote, good code example. It's a good idea to expose one's class
constants (static final primitive/String variables) through protected or
public methods, and keep the actual variables private. That's assuming
the constant needs to be exposed outside the class in the first place.

AHS
-- 
...wherever the people are well informed they can be trusted with their
own government...
-- Thomas Jefferson, 1789

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Global enums and constants Davej <galt_57@hotmail.com> - 2012-02-14 14:37 -0800
  Re: Global enums and constants Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-14 14:53 -0800
    Re: Global enums and constants Davej <galt_57@hotmail.com> - 2012-02-14 15:10 -0800
      Re: Global enums and constants Patricia Shanahan <pats@acm.org> - 2012-02-14 15:24 -0800
        Re: Global enums and constants Davej <galt_57@hotmail.com> - 2012-02-14 15:54 -0800
      Re: Global enums and constants Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-15 08:31 -0800
        Re: Global enums and constants Lew <lewbloch@gmail.com> - 2012-02-15 09:38 -0800
          Re: Global enums and constants Roedy Green <see_website@mindprod.com.invalid> - 2012-02-15 14:52 -0800
            Re: Global enums and constants Lew <lewbloch@gmail.com> - 2012-02-15 16:28 -0800
              Re: Global enums and constants Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-02-15 21:30 -0400
  Re: Global enums and constants Patricia Shanahan <pats@acm.org> - 2012-02-14 15:04 -0800

csiph-web