© Kishori Sharan and Adam L. Davis 2022
K. Sharan, A. L. DavisBeginning Java 17 Fundamentalshttps://doi.org/10.1007/978-1-4842-7307-4_22

22. Enum Types

Kishori Sharan1   and Adam L. Davis2
(1)
Montgomery, AL, USA
(2)
Oviedo, FL, USA
 
In this chapter, you will learn:
  • What enum types are

  • How to declare enum types and enum constants

  • How to use enums in switch statements

  • How to associate data and methods to enum constants

  • How to declare nested enums

  • How to implement interfaces to an enum type

  • How to perform a reverse lookup for enum constants

  • How to use EnumSet to work with ranges of enum constants

All example programs in this chapter are a member of a jdojo.enums module, as declared in Listing 22-1.
// module-info.java
module jdojo.enums {
    exports com.jdojo.enums; ...

Get Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.