constant, immutable
constant 修饰的变量需要在编译期确定值, 链上不会为这个变量分配存储空间, 它会在编译时用具体的值替代, 因此, constant常量是不支持使用运行时状态赋值的(例如: block.number, block.timestamp, msg.sender 等这些是不能用constant )。
constant 目前仅支持修饰 strings 及 值类型. 它更为节约gas
uint public constant NUM = 69;
immutable 修饰的变量是在部署的时候确定变量的值, 它在构造函数中赋值一次之后,就不再改变, 这是一个运行时赋值, 就可以解除之前 constant 不支持使用运行时状态赋值的限制.
uint immutable decimals;
uint immutable maxBalance;
IMasterChef public immutable MASTER_CHEF;
address public immutable owner = msg.sender;