What is constant folding in java compiler? [duplicate]

我与影子孤独终老i 提交于 2019-11-30 04:29:14

问题


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

Hi I have come across line Java compiler uses something known as Constant Folding.What is this? and how Does it affect?


回答1:


Constant folding is where the compiler finds expressions that contain compile-time constants and replaces them with the result effectively removing redundant runtime calculations.

// code
static final int a = 2;
int b = 30 * a;

// folding would create
int b = 60;



回答2:


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




回答3:


This explains it well http://en.wikipedia.org/wiki/Constant_folding



来源:https://stackoverflow.com/questions/2264178/what-is-constant-folding-in-java-compiler

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