KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have 2 jars, let's call them a.jar and b.jar. b.jar depends on a.jar. In a.jar, I defined a class, let's call it StaticClass. In the StaticClass, I defined a static block, calling a method named "init" : public class StaticClass { static { init(); } public void static init () { // do some initialization here } } in b.jar, I have a main, so in the main, I expect that the init() method has been called, but actually not. I suspect that is because the StaticClass has not been loaded by the jvm, could anyone tell me Is my conclusion correct? What triggers the jvm to load a class? How can I get the static block executed automatically? Thanks
Tags (comma-separated)
Save Edits
Cancel