I’m not asking if the tooling currently exists, I’m curious if there’s something inherent in .class files that would prevent static linking.
I’m not asking if the tooling currently exists, I’m curious if there’s something inherent in .class files that would prevent static linking.
It's not so much a problem with the .class files, instead it's a problem with reflection.
I can write `var foo = Class.forName("foo.bar.Baz")` which will cause the current class loader to look up and initialize the `foo.bar.Baz` class if it's available. I can then reflectively initialize an instance of that class by calling `foo.newInstance()`
Java has a ton of really neat meta-programming capabilities (and those will increase with the new ClassFile api). Unfortunately, those make static compilation and dead code elimination particularly hard. Tools that allow for static compilation (like graal) basically push the dev to declare upfront which classes will be accessed via reflection.
It's hard, and some might argue impossible, to statically analyze reachability in a dynamic language like java that allows for runtime class loading and redefinition. As it turns out, Java is much closer to javascript than C++ in terms of dynamic runtime behavior.
AOT compilation certainly doesn't give you the best outcome for all of these concerns (regardless of the language).