【问题标题】:What is constant folding in java compiler? [duplicate]java编译器中的常量折叠是什么? [复制]
【发布时间】:2010-02-15 05:34:03
【问题描述】:

可能重复:
is there any concept called “Constant Folding” in java?

嗨 我遇到了行 Java 编译器使用称为常量折叠的东西。这是什么?以及它如何影响?

【问题讨论】:

    标签: java core constantfolding


    【解决方案1】:

    常量折叠是编译器查找包含编译时常量的表达式并将其替换为有效消除冗余运行时计算的结果的地方。

    // code
    static final int a = 2;
    int b = 30 * a;
    
    // folding would create
    int b = 60;
    

    【讨论】:

      【解决方案2】:

      常量折叠是在编译时简化常量表达式的过程。常量表达式中的术语通常是简单的文字,例如整数 2,但也可以是值从不修改的变量,或显式标记为常量的变量

      【讨论】:

        猜你喜欢
        • 2012-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-13
        • 1970-01-01
        • 2018-02-03
        相关资源
        最近更新 更多