Hex constants

How do you create public constants in Haxe? I just need an analogue of the good old constant in AS3:

public class Hello
{
     public static const HEY:String = "hey";
}

      

+5


source to share


2 answers


The usual way to declare a constant in Haxe is to use static inline

modifiers.

class Test {
    public static inline var CONSTANT = 1;

    static function main() {
        trace(CONSTANT);
        trace(Test.CONSTANT);
    }
}

      



look at try.haxe.org .

+16


source


For non-static variables and objects, you can give them a shallow constant like below:

public var MAX_COUNT(default, never):Int = 100;

      



This means that you can read the default, but you cannot "write" to it.

More information can be found at http://adireddy.github.io/haxe/keywords/never-inline-keywords .

+5


source







All Articles