Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 2, pg 75-76, switch statements (Java OCA 8 Programmer I Study Guide, Sybex)

 
Tami Wakana
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For switch statements, I understand enum constants are allowed




I understand why they all don't compile. I'm wondering what an enum constant would look like (the last one doesn't compile because it is an enum value, not a constant)

[edited to fixed code tags]
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tami Wakana wrote:I'm wondering what an enum constant would look like (the last one doesn't compile because it is an enum value, not a constant)

Last one doesn't compile because cannot convert from enum DayOfWeek to String i.e. firstName means expecting String found enum
Here  java.time.DayOfWeek.SUNDAY is enum constant. They used fully qualified name of enum constant SUNDAY.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tami,
Enums aren't in the OCA. You'll learn this for the OCP. But here's a preview:

This is an enum


And this is a switch statement that uses the enum
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic