开发者

What is constant folding in java compiler? [duplicate]

开发者 https://www.devze.com 2022-12-20 08:14 出处:网络
This question already has answers here: 开发者_如何学Go Closed 12 years ago. Possible Duplicate: is there any concept called “Constant Folding” in java?
This question already has answers here: 开发者_如何学Go Closed 12 years ago.

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?


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;


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

0

精彩评论

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

关注公众号