1
所以,問題在標題中。我使用'never'關鍵字在我的類中聲明瞭一些屬性,所以我可以在構造函數中只設置一次這些屬性的值。不過,我得到以下錯誤:'永不'屬性不能在迴路中設置
無法訪問字段或標識%名稱%編寫有問題的代碼
例子:
class TreeAbility
{
public var id(default, never):String;
public var maxLvl(default, never):Int;
public function new(id:String, maxLvl:Int)
{
Assert.assert(maxLvl > 0);
this.id = id; (*)
this.maxLvl = maxLvl; (*)
this.currentLvl = 0;
}
}
的線標有(*)拋出訪問錯誤
_never_詳細介紹舊版本的網站。它還包含向構造函數內的永不寫屬性賦值的示例。 但是,好的,也許_never_在過去的某個時間以這種方式工作 http://old.haxe.org/ref/properties – Gulvan
只需閱讀4.0.0更新日誌。現在我假設在構造函數中只能設置靜態永不寫屬性 – Gulvan
在舊網站上,我看到使用「never」屬性的示例未寫入「numItems」。 「container.numItems」將在後臺調用「get_numItems()」,但最終代碼中的實例中不存在名爲「numItems」的變量。 –