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 编辑器假定每个 global class 都是可实例化的,但泛型类型无法被实例化,因为类型参数未被绑定。
// 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]
是一个常见错误,而此警告有助于提醒用户,这可能会导致意外错误。