开发者

Core Java Static Variables Loading [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overl开发者_开发问答y broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

Is there a way to stop static variable from being loaded into memory?

Thanks,


You can stop a static variable loading by not loading the class, or having the static initializer throw an exception/error. Either way the class is unusable.

If you have a compiled class and you want to change the way it loads, you can decompile it and change it manually or use byte code manipulation at runtime. The first option is likely to be simpler.


If you do not need them anyways, why don't you remove them?

If you do need them, but only at a much later point, and they are so large that optimization really makes sense, use lazy initialization. For this, you can for instance use Lombok's annotation @Getter(lazy=true) (which implements the double-check idiom, see Effective Java Item 71).


There is a strict order of initialization so it cannot be postponed for later.

I do not know if ripping the variables from bytecode can be done and what is the required effort.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜