From: Wojtek on
Lew wrote :
> Wojtek wrote:
>> I am not confused at all. If it is static and final, then it is a class
>> constant. The fact that it has attributes which can be modified (if
>> exposed) is a moot point. The _reference_ cannot be changed, and so it is a
>> constant.
>
> That is not the definition of a class constant! The JLS defines the term.
> It is an extremely important distinction; initialization of class constants
> and their storage differs from other 'static final' variables.
>
> You are not using the correct definition.
> <http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#10931>
>> We call a variable, of primitive type or type String, that is final and
>> initialized with a compile-time constant expression (�15.28) a constant
>> variable. Whether a variable is a constant variable or not may have
>> implications with respect to class initialization (�12.4.1), binary
>> compatibility (�13.1, �13.4.9) and definite assignment (�16).

So it is limited to primitives or String. Ok, then what would you call
this? Like String it is barred from being modified after
initialisation.

--------------------------------
public class Foo
{
public static final MyObject OBJECT_SOME = new MyObject("some parm");
public static final MyObject OBJECT_TWO = new MyObject("two parm");

public class MyObject()
{
private String parm;

private MyObject(String parm )
{
this.parm = parm;
}

public String getParm()
{
return this.parm;
}
}
}

....

System.out.println(Foo.OBJECT_SOME.getParm());

--------------------------------

What is OBJECT_SOME?

If there is a name for this, then that is what I will start calling
these constructs, otherwise...

--
Wojtek :-)


From: Peter Duniho on
Lew wrote:
> If John jumped off a bridge, would you do that, too?

I dunno. I wouldn't do that for just anyone. But John's a pretty smart
guy; if I see him doing something, I might wonder if there might
actually be something to it after all. :p
From: John B. Matthews on
In article <Kq2dnfl-9NMs5P7WnZ2dnUVZ_qBi4p2d(a)posted.palinacquisition>,
Peter Duniho <NpOeStPeAdM(a)NnOwSlPiAnMk.com> wrote:

> Lew wrote:
> > Peter Duniho wrote:
> >> Joshua Block...
> >
> > It's Joshua Bloch, not Joshua Block. Get it right, please.
>
> Uh, I admit I misspelled his name. But, I simply used the same spelling
> John originally posted. Why single me out?

Egad, you're right, and I've done it before! I have a clear memory of
thinking "out of respect for the esteemed name of Bloch, I won't do
_that_ again." Worse, I was relieved that it was you and not me. Hubris
and Schadenfreude. Apologies.

> Though, I admit…between the spelling of a person's name and the coding
> conventions used in code not relevant to an actual project you're
> working on, the former is much more worthy of mention. :p

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
From: Lew on
Wojtek wrote:
> public class Foo
> {
> public static final MyObject OBJECT_SOME = new MyObject("some parm");
> ...
> --------------------------------
>
> What is OBJECT_SOME?
>
> If there is a name for this, then that is what I will start calling
> these constructs, otherwise...

I don't know what others call it, but I call it a "static final member", or if
not mutable, an "immutable member".

The problem with the upper-case name is that it implies but does not guarantee
immutability. If it happens that a 'MyObject' instance is mutable, then the
upper-case name is misleading at best.

In your particular code 'MyObject' instances are immutable, but that is not
discernible from the name alone. For those types that the JLS allows to be
"constant" there is no mystery. OTOH, you seem to be rigorous in ensuring
that something named with upper-case letters is immutable, so in your code I'd
have more faith. I'd have even more faith if you provided Javadocs for the
public members that asserted the immutability.

--
Lew
From: Lew on
Peter Duniho wrote:
> Lew wrote:
>> If John jumped off a bridge, would you do that, too?
>
> I dunno. I wouldn't do that for just anyone. But John's a pretty smart
> guy; if I see him doing something, I might wonder if there might
> actually be something to it after all. :p

That is a very measured and respectable answer. If you had added, "Provided
my ankles were secured by a bungee cord," I'd see why you were willing to
follow suit.

--
Lew