Haxe中的局部常量-可能
我知道Haxe 中有一个关于类属性的常量问题。我的问题是:是否可以在函数内部定义常量?喜欢:
function foo(){
const bar=7;
bar = 8; // should prevent compilation
}
也许像 var 之类的var foo:ReadOnlyInt东西?
回答
您正在寻找final.
function foo() {
final bar = 7;
bar = 8; // not allowed
}
https://haxe.org/manual/expression-var.html