is there any concept called “Constant Folding” in java?

大憨熊 提交于 2019-11-26 18:36:37

问题


is there any concept called "Constant Folding" in java? if yes what is it?


回答1:


Constant folding is the process of simplifying constant expressions at compile time. Terms in constant expressions are typically simple literals, such as the integer 2, but can also be variables whose values are never modified, or variables explicitly marked as constant

Yes, it's exists on Java: Compiler optimizations




回答2:


Yes, there is.

From this JavaWorld article (which you could've googled yourself!):

static final int length = 25;
static final int width = 10;
int res = length * width;

Execution time is not used to multiply those values; instead, multiplication is done at compile time. The code for the following variable assignment is modified to produce bytecode that represents the product of width and length:

int res  = 250;


来源:https://stackoverflow.com/questions/2012528/is-there-any-concept-called-constant-folding-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!