Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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: 39540
778
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.
 
Saloon Keeper
Posts: 6246
58
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.
 
Saloon Keeper
Posts: 21139
134
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
Saloon Keeper
Posts: 6246
58
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
Saloon Keeper
Posts: 21139
134
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: 65842
250
  • 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
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!