【发布时间】:2010-02-15 05:34:03
【问题描述】:
可能重复:
is there any concept called “Constant Folding” in java?
嗨 我遇到了行 Java 编译器使用称为常量折叠的东西。这是什么?以及它如何影响?
【问题讨论】:
标签: java core constantfolding
可能重复:
is there any concept called “Constant Folding” in java?
嗨 我遇到了行 Java 编译器使用称为常量折叠的东西。这是什么?以及它如何影响?
【问题讨论】:
标签: java core constantfolding
常量折叠是编译器查找包含编译时常量的表达式并将其替换为有效消除冗余运行时计算的结果的地方。
// code
static final int a = 2;
int b = 30 * a;
// folding would create
int b = 60;
【讨论】:
常量折叠是在编译时简化常量表达式的过程。常量表达式中的术语通常是简单的文字,例如整数 2,但也可以是值从不修改的变量,或显式标记为常量的变量
【讨论】: