首页 > 解决方案 > Haxe 中的局部常量 - 可能

问题描述

我知道在 Haxe 中有关于类属性的常量问题。我的问题是:是否可以在函数内部定义常量?像:

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

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

标签: haxe

解决方案


你正在寻找final.

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

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


推荐阅读