Anand Jain wrote:I have heard that we should use enums rather than contants. Can somebody please explain me the advantages of using enums over constants?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Anand Jain wrote:I have heard that we should use enums rather than contants. Can somebody please explain me the advantages of using enums over constants?
I think what you may have heard is that you should use enums over primitive constants.
The main reason for this is that an enum constant can't be mistaken for something else, whereas an (eg) int value can. Enums also have several useful structures, such as EnumSet for comparing sets of constants.
HIH
Winston
Winston Gutkowski wrote:
Anand Jain wrote:I have heard that we should use enums rather than contants. Can somebody please explain me the advantages of using enums over constants?
I think what you may have heard is that you should use enums over primitive constants.
The main reason for this is that an enum constant can't be mistaken for something else, whereas an (eg) int value can.
Anand Jain wrote:
Hi..Thanks for the reply..do you mean to say enums provide type safety which primitive constants don't provide?
Jeff Verdegan wrote:Actually, that's another case I missed, and it applies not just to primitives, but to Strings as well.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Anand Jain wrote:Hi..Thanks for the reply..do you mean to say enums provide type safety which primitive constants don't provide?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here