> If it was "relatively easy" then there wouldn't be a million dependency injection solutions for Java of ungodly runtime cost to try and solve this problem.
You realize Java has the feature you're discussing, without dependency injection?
That runs at class load time, not at library/executable load time as c++ static constructors or __attribute__((constructor)) does.
So no, that's not equivalent. Not even close. This is why you see things in Java that scan through loaded jars looking for all classes with attributes to just speculatively load. To recreate what c++ has natively & C has with a broadly supported extension.
You realize Java has the feature you're discussing, without dependency injection?
They even have a well defined execution order:https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.htm..., section 8.7, with order defined in section 12.4