Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there any concept called "Constant Folding" in java?

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

like image 647
GuruKulki Avatar asked Oct 23 '25 16:10

GuruKulki


1 Answers

Yes, there is.

From this JavaWorld article:

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;
like image 99
Bozho Avatar answered Oct 25 '25 06:10

Bozho