1

I would like to write this pattern:

enum Foo {
  ABC(SHARED_DATA),
  DEF(SHARED_DATA);
  GHI(ImmutableList.of(4));

  private static final List<Integer> SHARED_DATA = ImmutableList.of(3);

  Foo(List<Integer> data) {
    this.data = data;
  }

  public static final List<Integer> data;
}

Am I guaranteed SHARED_DATA is initialized in time?

djechlin
  • 59,258
  • 35
  • 162
  • 290
  • 1
    Did you look into http://stackoverflow.com/questions/20619950/why-do-static-and-instance-init-blocks-in-enums-behave-differently-from-those-in or http://stackoverflow.com/questions/11419519/enums-static-and-instance-blocks ? – GhostCat Dec 16 '16 at 20:00

0 Answers0