All Articles

enums IV

So you find yourself calling values() lots in your code. Since this allocates a new array every time and this does not get optimized away, you might want to create a local copy, or an immutable collection and use that instead:

public enum Day {
  MONDAY, TUESDAY;

  private static final Day[] values = values();

  ...
}

or alternatively use an immutable Set.