Skip to Content
Effective Java, 3rd Edition
book

Effective Java, 3rd Edition

by Joshua Bloch
December 2017
Intermediate to advanced
416 pages
13h 31m
English
Addison-Wesley Professional
Content preview from Effective Java, 3rd Edition

Chapter 6. Enums and Annotations

JAVA supports two special-purpose families of reference types: a kind of class called an enum type, and a kind of interface called an annotation type. This chapter discusses best practices for using these type families.

Item 34: Use enums instead of int constants

An enumerated type is a type whose legal values consist of a fixed set of constants, such as the seasons of the year, the planets in the solar system, or the suits in a deck of playing cards. Before enum types were added to the language, a common pattern for representing enumerated types was to declare a group of named int constants, one for each member of the type:

// The int enum pattern - severely deficient! public static ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Effective Java, 2nd Edition

Effective Java, 2nd Edition

Joshua Bloch
Learning Java, 6th Edition

Learning Java, 6th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Head First Java, 3rd Edition

Head First Java, 3rd Edition

Kathy Sierra, Bert Bates, Trisha Gee
Head First Java, 2nd Edition

Head First Java, 2nd Edition

Kathy Sierra, Bert Bates

Publisher Resources

ISBN: 9780134686097