If statement 在Haxe中的if语句中使用对象的存在性

If statement 在Haxe中的if语句中使用对象的存在性,if-statement,conditional-statements,haxe,If Statement,Conditional Statements,Haxe,您可以使用对象的存在作为Haxe中if语句的条件吗?如果是,怎么做 var b : Bullet = collide("bullet", x, y); if (b) { b.destroy(); } 我还试着用Null类型测试它,但这似乎不起作用。正如kirilloid在评论中提到的,试着检查b是否为Null: var b : Bullet = collide("bullet", x, y); if (b != null) { b.destroy(); } 出于多种原因,Haxe决定

您可以使用对象的存在作为Haxe中if语句的条件吗?如果是,怎么做

var b : Bullet = collide("bullet", x, y);
if (b) {
  b.destroy();
}

我还试着用
Null
类型测试它,但这似乎不起作用。

正如kirilloid在评论中提到的,试着检查
b
是否为Null:

var b : Bullet = collide("bullet", x, y);
if (b != null) {
  b.destroy();
}

出于多种原因,Haxe决定不使用
if(b)
语法。您可以在上找到关于此主题的讨论。

如果(b!=null)
应该有效吗。资本化将是我的末日。谢谢陷阱警告:Haxe的灵活性导致了与null相关的一些特殊行为。