Description
I have a static member being initialized inside an enum:
class Foo { ... enum Bar { FIRST("foo") ... static final Set<String> barNames = new HashSet<String>() ... Bar(String name) { barNames.add(name) ... } ... } ... }
However, when the code above executes, barNames is null inside the constructor, i.e., the static member of the enum class is not initialized before the enums themselves are initialized. This may not be a bug, but it seems to me there should be some documentation and/or a compiler warning if you do this.
Instead, I had to move the set outside the enum to the enclosing class.
Attachments
Attachments
Issue Links
- relates to
-
GROOVY-10721 Unexpected static initialization order
- Open