Haxe中方法内的条件编译

And*_*een 1 haxe

在Haxe编程语言中,是否可以在方法定义中检测目标语言,如下所示?

class Test {
    static function main() {
        trace("Hello World !");
        #if java
            trace("This is compiled to Java");
        #elseif js
            trace("This is compiled to Javascript");
    }
}
Run Code Online (Sandbox Code Playgroud)

Fra*_*lli 5

这应该工作,你只需要在最后一次跟踪后添加#end.