ning/killbill — comment on commit 848d61f2efa2e158c7f1a43ec6dee89617700416
File: entitlement/src/main/java/com/ning/billing/entitlement/api/user/Subscription.java line 101
By tomdz:

The simplest reason of why statics are evil is that they create state that is shared across threads of execution (within the same classloader). This in effect means that all the shared state (objects reachable by the injectormagic in this case) has to be thread safe which can add a lot of overhead (because it is transitive).
Another problem is that this makes testing a lot harder. InjectorMagic seems to store the first injector that is set on it and ignore any future attempts to set an injector. Now imagine two tests (not necessarily in the same class) running in the same VM (e.g. in the IDE) that use guice to setup their test. The second now will use the injector of the first one, which will most likely cause weird errors in both tests as they affect each other's state.

In this particular case, the oldie-but-goldie Factory pattern might be a better choice. I.e. have an IAccountFactory and AccountFactory implementation which keeps references to all objects that the account might need (e.g. the DAOs) and is itself created by guice. No statics necessary. Now of course you need to create the account using the factory, you can't just say new Account(...), but that is a small price to pay, especially since you now can also have a MockAccountFactory.