static initializers considered harmful

October 16th, 2005

One Response to “static initializers considered harmful”

  1. F.Baube Says:

    I tried to use static initializers to build a tree structure of more-complex objects that have multiargument constructors, and to build the tree structure, most of these static initializers were calling constructors with other statically-initialized objects as arguments. I found that it gets pretty hairy in a hurry and it requires a LOT of experimentation. Worse, I would be pessimistic whether such a system would work identically in another JVM. At some point I gave up, and instead I let the static initializers do their thing but without so many references to other objects, and then right after startup I walk the object graph and create the tree structure that I need.

Leave a Reply