当前位置:首页 > 开发 > 编程语言 > Java > 正文

Java常量内联的编译优化条件

发表于: 2013-04-10   作者:aigo   来源:转载   浏览:
摘要: 原文:http://stackoverflow.com/questions/9082971/java-compile-time-constants-and-variables   Compile time constant must be: declared final primitive or String initialized within declaratio

原文:http://stackoverflow.com/questions/9082971/java-compile-time-constants-and-variables

 

Compile time constant must be:

  • declared final
  • primitive or String
  • initialized within declaration
  • initialized with constant expression

So private final int x = getX(); is not constant.

To the second question private int y = 10; is not constant (non-final in this case), so optimizer cannot be sure that the value would not change in the future. So it cannot optimize it as good as constant value. The answer is: No, it is not treated the same way as compile time constant.

Java常量内联的编译优化条件

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号