How to get value of string via Reflection?

I have variable “img : String” and I try ot get the value, but get empty string. Example:

class Test {
    static function main() {
        new Test2().me();

class Test2 {
    public function new()
    var img : String = "this is haxe";
    public function test() {


Do you mean Test2 ().test () or is me another function?

Yes, Test2().test is the correct function. My mistake has dead-code elimination enabled by default. img was not referenced anywhere, so it removed it. Adding @:keep to a class or field that is only referenced by reflection can help

1 Like

Thank you !!! It really works