Effective Java! Use Enums Instead of int Constants
With this chapter we leave the discussion of Generics behind and move on to talking about enums
. Let's start with what our code may look like without enums
. Let's say we have a finite set of types of fruits that we need to represent in our code. We may decide to do the following:
public static final int APPLE_FUJI = 1;
public static final int APPLE_GRANNY_SMITH = 2;
public static final int APPLE_PIPPEN = 3;// Somewhere else in the codepublic static final int ORANGE_NAVEL = 1;
public static…