You have strange behavior due to the Integer
data type. Regarding JLS 12.4.2 static fields are initialized in the order you write it, BUT compile-time constants are initialized first.
If you do not use the wrapper type Integer
but the int
type, you get the behavior you want.