What is a Java enum

 

Java Enums

 Java  enum is a special  Java "class" that represents a group of constants (unchangeable variables, like final variables).

Java enum is for instance : 

3 constant values e.g. Blue, Pink, Red 

or e.g. the 12 months of the year 

or the 7 days of the week etc. 

Java  enums save you typing the values.

One can get the value from the Java  enum. 

Java  enums avoid spelling errors and provide consistancy.

To create: 

enum Level {
  BAD,
  WORSE,
  TERRIBLE
}

To use: 

Level myLevel = Level.BAD;

Comments

Popular posts from this blog

The Seven Different Types of Coding Blocks in Java

What is a web application? (Lesson 7 of our Java Bootcamp)

How big is an int in Java