2 ms·
It's true the JVM specifies this, but it doesn't mean it's always easy or nice to figure out what's going on. For example class A { static final int x = B.y
by aardvark179 9y ago
It's true the JVM specifies this, but it doesn't mean it's always easy or nice to figure out what's going on.
For example
class A { static final int x = B.y; static final int y = 1; }
class B { static final int x = A.y; static final int y = 2; }
will not produce any static initializers and will do what you probably wanted because everything can be turned into a class constant and resolved at compile time. However this
class A { static final Integer x = B.y; static final Integer y = 1; }
class B { static final Integer x = A.y; static final Integer y = 2; }
will not work the way you might want because there is no order in which the static initializers can be run that will do everything in the correct order.