Seems like a gaping omission in a guide that claims to be about "modern" Java.
Seems like a gaping omission in a guide that claims to be about "modern" Java.
It's a tradeoff between two different kinds of clarity. Yes, it's harder to see the "whole wiring" without better tools...
But it makes small, encapsulated classes much easier to reason about and develop! You can focus on assuring: "My `Foo` can interact with a supplied `Bar`" rather than dealing with all sorts of crap about what implementation of `Bar` it gets or how that `Bar` instance is configured.
I'm looking at you, Spring.
Most DI frameworks automatically configure, and register objects. So literally all you need to add is the annotation.
Then you can override the automatic registration with you own, with different implementation when required.
Substitution for testability should be done at the runtime level, substituting class references as needed, instead of punishing all production code everywhere.
That would require a Java agent. And that's a smell it its own right. (Cf JMockit)