Whats up with static memory in java?

前端 未结 6 512
情深已故
情深已故 2020-12-02 19:17

This question is for the java language in particular. I understand that there is a static protion of memory set aside for all static code.

My question is how is this

6条回答
  •  执念已碎
    2020-12-02 19:55

    This static variable some0 is initialized as soon as your class is referenced in your code. In your example this will be executed in first line of your main method.

    You can validate this by creating a static initializer block. Put a break point in this initializer block and you'll see, when it will be called. Or even more simplier... put a breakpoint in the constructor of SomeObject.

提交回复
热议问题