Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
GD0402:類別不可為泛型類別
規則 ID |
GD0402 |
分類 |
用法 |
修正是否會破壞相容性 |
破壞性變更 |
預設啟用 |
是 |
原因
泛型型別被標註為 [GlobalClass] 屬性。
規則說明
Godot 編輯器假設每個 全域類別 都可以實體化,但泛型類別因型別參數未綁定,無法直接實體化。
// This type is a valid global class because it's not generic.
[GlobalClass]
class SomeType : Node { }
// This type is not a valid global class because it's generic.
[GlobalClass]
class SomeGenericType<T> { }
修正方式
要修正此規則的違規情形,請將型別移除泛型參數,或移除 [GlobalClass] 屬性。
什麼時候應該忽略警告
請勿忽略此規則的警告。將 [GlobalClass] 加到泛型類別很容易出錯,此警告可協助使用者避免導致不可預期錯誤。