简体   繁体   English

Haxe使用@:classCode

[英]Haxe use of @:classCode

I can't find a single example of how @:classCode is used (to inject a native member directly into the file). 我找不到一个如何使用@:classCode示例(将本机成员直接注入文件)。 This fails with Unexpected untyped at compile time: 这在编译时出现Unexpected untyped失败:

@:classCode
untyped __java__("public void paintComponent(Graphics g) {doStuff();}"); 

I can't simply use standard Haxe code to have a paintComponent() method because of the way Haxe eats @:overload methods (and forces use of @:overload in the first place). 我不能简单地使用标准的Haxe代码来使用paintComponent()方法,因为Haxe吃@:overload方法(并且首先强制使用@:overload )。

There are some examples of it in the Haxe standard library , for instance: 在Haxe标准库中有一些例子,例如:

@:classCode('override public string Message { get { return this.toString(); } }\n\n')
@:nativeGen @:keep @:native("haxe.lang.HaxeException")
private class HaxeException extends Exception

Looks like the class code metadata has a string argument containing the code to be inserted and should be used on a class declaration. 看起来类代码元数据有一个包含要插入的代码的字符串参数,应该在类声明中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM