Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is constant folding in java compiler? [duplicate]

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?

like image 728
giri Avatar asked Feb 15 '10 05:02

giri


1 Answers

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;
like image 157
Nick Bedford Avatar answered Sep 20 '22 13:09

Nick Bedford