【问题标题】:Local constants in Haxe - possibleHaxe 中的局部常量 - 可能
【发布时间】:2021-02-19 19:43:12
【问题描述】:

我知道有一个关于类属性的问题Constants in Haxe。我的问题是:是否可以在函数内部定义常量?喜欢:

function foo(){
   const bar=7;
   bar = 8; // should prevent compilation
}

也许像 var var foo:ReadOnlyInt 之类的东西?

【问题讨论】:

    标签: haxe


    【解决方案1】:

    您正在寻找final

    function foo() {
       final bar = 7;
       bar = 8; // not allowed
    }
    

    https://haxe.org/manual/expression-var.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多