In the official Java guide “Programming with assertions” it is stated that
(last paragraph on the page)
Few programmers are aware of the fact that a class’s constructors and methods can run prior to its initialization. When this happens, it is quite likely that the class’s invariants have not yet been established, which can cause serious and subtle bugs.
What is meant by this? When does this happen? Is it something I have to care about in my daily use of Java?
Basically, they talk about the following situation:
As you can see, in this case constructor runs before initializer of the static field
s, i. e. prior to the full initialization of the class. It’s just a simple example, but it can become more complex when multiple classes are involved.It’s not something you can often see in your everyday work, but you need to be aware of this possibility and avoid it when writing code.