Hacker News new | past | comments | ask | show | jobs | submit login

> 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?

   class Foo {
      static {
           initialize();
      }
    }

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




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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: