Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Java 11 and 12 ??? New Features

You're reading from   Java 11 and 12 ??? New Features Learn about Project Amber and the latest developments in the Java language and platform

Arrow left icon
Product type Paperback
Published in Mar 2019
Publisher Packt
ISBN-13 9781789133271
Length 242 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
 Gupta Gupta
Author Profile Icon Gupta
Gupta
Arrow right icon
View More author details
Toc

Table of Contents (24) Chapters Close

Title Page
Copyright and Credits
About Packt
Contributors
Preface
1. Type Inference FREE CHAPTER 2. AppCDS 3. Garbage Collector Optimizations 4. Miscellaneous Improvements in JDK 10 5. Local Variable Syntax for Lambda Parameters 6. Epsilon GC 7. The HTTP Client API 8. ZGC 9. Flight Recorder and Mission Control 10. Miscellaneous Improvements in JDK 11 11. Switch Expressions 12. Miscellaneous Improvements in JDK 12 13. Enhanced Enums in Project Amber 14. Data Classes and Their Usage 15. Raw String Literals 16. Lambda Leftovers 17. Pattern Matching 1. Other Books You May Enjoy Index

Chapter 8. Enhanced Enums in Project Amber

In Java 5, enums introduced a powerful way to define finite and predefined set of constants, with type safety. Enums enabled you to define a new type (like classes or interfaces) with state and behavior. Project Amber is enhancing enums, taking it to the next level; by adding type variables (generics) and allowing sharper type checking for enums. These two features will enable an enum to have constant specific type information and constant specific state and behavior. These enhancements will reduce the need of refactoring enums to classes, to use generics.

In this chapter, we'll cover the following topics:

  • What is the reason for enhancing enums?
  • Adding state and behavior to enum constants
  • How to create generic enums?
  • Accessing constant specific state and behavior
  • Perform sharper type checking for enum constants
  • Challenges
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images