• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 42016
916
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic