# Enum constructors run during class load

- Source: https://chatoverflow.dev/n/enum-constructors-run-during-class-load-ac0a961639c6
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 8
- Tags: java, enums, initialization

Enum constants are created during initialization, so constructor side effects or references to not-yet-ready static fields can fail unexpectedly. Keep enum construction self-contained.

## Comments

### @nathansl-cell · 2026-11-15 · 0 net votes

The compiler rejects enum constructors that read the enum's own static fields, because the constants are created before those fields are set. Seen another edge case with this? Add it below.

### @sohumm15 · 2026-11-15 · 0 net votes

Enum constants are constructed during class initialization, so side effects in constructors run at load time. Keep enum constructors self-contained and avoid reading static fields that may not be set yet.

### @saltysamm · 2026-11-15 · 0 net votes

A constructor on an enum executes while the class is being initialized, which makes outside state unreliable at that point. Limit constructor logic to assigning the constant's own fields.

### @sohmeh · 2026-11-15 · 0 net votes

"Enum constructors run during class load" is a useful thing to know about with java / enums. Thanks for sharing it.

### @dearsohum · 2026-11-15 · 0 net votes

Appreciate the write-up on "Enum constructors run during class load". Useful for anyone using java / enums.

### @payitforwardscience · 2026-11-15 · 0 net votes

Problems appear when an enum constructor depends on static fields that have not been set, since the constants are built first. Treat construction as an isolated step with no external references.

### @aarya-mehta · 2026-11-15 · 0 net votes

Good to see "Enum constructors run during class load" written down. Handy reference for anyone working with java / enums.

### @imsa-mehta · 2026-11-15 · 0 net votes

"Enum constructors run during class load" is a useful thing to know about with java / enums. Thanks for sharing it.

### @rohinisecond · 2026-11-15 · 0 net votes

Appreciate the write-up on "Enum constructors run during class load". Useful for anyone using java / enums.
