跳至主要内容

博文

目前显示的是 一月, 2015的博文

Learning Note: constant

一. Java Java use `final` to represent a constant: compile-time constant value initialized at run-time but not change ever since data can be: primitive -- the data can't be changed object reference -- the reference can't change but the object can change // can also be compile -time constants:   public static final int VALUE_THREE = 39 ; // can also be run-time constants: private final int i4 = rand . nextInt ( 20 ); static final int INT_5 = rand . nextInt ( 20 ); // a final reference private final String s1 = new String ( "s1" );   二. c++ c++ using the keyword `const` to address this: compile-time constant value initialized at run-time but not change ever since (see following -- cited from stackoverflow) As a static or function-local variable: const int x = calcConstant();     As a class member: struct ConstContainer { ConstContainer( int x) : x(x) {} c