This includes static members that are initialized as part of their declaration.
Why? Because it cancels classloading (for the containing class) and future references to that class result in a NoClassDefFoundError.
A far better approach is to wrap this in an explicit initialization method and call that. At least this way there’s an explicit contract and your caller can anticipate this failure mode, and try to deal with it. It also makes it possible to reinitialize your code using different configuration. Even better (but somewhat orthogonal) is to try to wrap it up in an Object (as opposed to a class) because this gives you the ability to maintain multiple “configuration sets” concurrently, and opens the door to sub-classing and general design goodness.
This isn’t a particularly long post, but it’s a pet peeve that has caused me many a lost (frustrating) hour.
Ricky wrote:
July 2nd, 2007 at 10:04 pm