如何将类名作为字符串?

Sam*_*bri 6 haxe

我如何在字符串中获取类名?

我试过这个:

Type.getClassName(this));
Run Code Online (Sandbox Code Playgroud)

这是我所在的当前课程,但我收到错误:

com.SubWidget should be Class<Dynamic>
Run Code Online (Sandbox Code Playgroud)

有帮助吗?

Mar*_*nol 12

你应该传递ClassType.getClassName.所以,首先抓住使用Type.getClass,像这样:

http://try.haxe.org/#6A196

class Test {
    static function main() new Test();

    function new()
    {
        var className = Type.getClassName(Type.getClass(this));
        trace('Current class name = $className');
    }
}
Run Code Online (Sandbox Code Playgroud)

另请参阅:http://api.haxe.org/Type.html#getClassName