Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enum references

 
Kendall Ponder
Ranch Hand
Posts: 205
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why don't I need the E. notation for the enum case values? It is required for the switch value. I assume it has to do with the case values being assigned at compile time and the switch value is assigned at run time.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kendall Ponder wrote:Why don't I need the E. notation for the enum case values? It is required for the switch value. I assume it has to do with the case values being assigned at compile time and the switch value is assigned at run time.

You can not use the type of the enum in the switch labels. It must be only the enum constant name! Adding the enum type is quite useless, because the enum is a set of predefined constants. So it can only be one of these constants, no need to qualify them with the enum type. If you try to do so, you'll get a compiler error.For those who are keen about the JLS, it's mentioned in the section about the switch statement.


Hope it helps!
Kind regards,
Roel
 
Kendall Ponder
Ranch Hand
Posts: 205
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic