• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Enum Type Gone Wrong

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all at the JavaRanch Forums,

I'm looking at an compiling error as to why the following program is not working with cone1 variable. It's the same code from above but for some reason it's saying that cone1 is not initiated.



Is there a reason for this?
 
author & internet detective
Posts: 39341
755
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I compile, I get an error that cone3 is not initialized. (cone1 is fine).

And the compiler is correct. Nowhere in this code is cone3 assigned a value.
 
Bartender
Posts: 5902
57
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The convention with enums is that the names be in all upper case with underscores to separate words if necessary, e.g. VANILLA.
 
Bartender
Posts: 20833
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:The convention with enums is that the names be in all upper case with underscores to separate words if necessary, e.g. VANILLA.



Eh, not really. That's a convention inherited from C, where it's applied to constants, but enums typically not so much, since the enum type ("class name") is generally considered to be sufficient to alert the reader..

 
Carey Brown
Bartender
Posts: 5902
57
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:

Carey Brown wrote:The convention with enums is that the names be in all upper case with underscores to separate words if necessary, e.g. VANILLA.



Eh, not really. That's a convention inherited from C, where it's applied to constants, but enums typically not so much, since the enum type ("class name") is generally considered to be sufficient to alert the reader..


Not if you use static imports. Best to stick with the constants convention.
 
Tim Holloway
Bartender
Posts: 20833
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, there's no real standard, even in C++, where you'll see plenty of examples of lower-case only (stop, start, pause), Leading-upper-case (Sunday, Monday, Tuesday), and const-style (LOW, HIGH).

Since the usage of enum values is extremely constricted, it's never been considered necessary to form a sort of "Hungarian Notation" for enums. Because even if you've hidden the import, the compiler will let you know if you're mis-using enum values.

Actually, if C had originally had "const", the all uppercase convention might never have been adopted. I think it was really a defense against the old "constants - aren't, and variables - won't" problem. Assigning to a name that's all in upper-case is obviously going to set off an alarm. But with a const (or final) qualifier, the compiler has taken over that job.
 
Marshal
Posts: 64638
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:. . . constants - aren't, and variables - won't . . .

That would appear to be a C/C++ problem, discussed here, though I would blackball that link because they can't spell “Ritchie”
 
Jennifer Swatson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

Thank you for your replies, I was able to solve the issue
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!