Seven Low-Cost Ways to Improve Legacy Code
Subject:   Enums and "Constant Object"
Date:   2004-10-28 08:53:34
From:   dubwai
Response to: Enums and "Constant Object"

"As for the term "type-safe-enum" I personally think that would cause confusion since the code is not exactly declaring an enum (which has other semantics as well) but merely several objects that cannot be changed (IE constant)."

My mistake. The term is 'type-safe enumeration'. I call it a typesafe enum as an abbreviatioon and becasue there are no 'enums' in pre 1.5 Java (and arguably even in 1.5.)

"There is no convention that says that only integral and string and other primitive types are the only kinds of things that are constant."

String isn't a primitive type. Really what you are talking about are 'literals'. There are no constants in Java. We call static finals 'constants' because they work like them. If the 'const' keyword is ever introduced into Java (unlikely, I think) this will really be confusing.

"A constant is simply something that can not be changed; the antithesis of variable."

Well, not exactly but in any event using the term constant confuses developers because it implies that marking a reference constant makes the Object it references unchangeable. I can't even count how many times I've seen people confused about why Strings are Objects but act like primitives.

1 to 1 of 1
1 to 1 of 1