#2408 setting enum ords

elyashiv Mon 13 Apr 2015

In c++ I used to do something like this:

enum direction
{
   Up = 13,
   Down = 10,
   Left = 23,
   Right = 20
};

There doesn't seem to be a way to do this in fantom. Can be added?

SlimerDude Mon 13 Apr 2015

You can add fields to enums like this:

enum class Direction {
    up(13),
    down(10),
    left(23),
    right(20);

    const Int code;
	
    private new make(Int code) {
        this.code = code
    }
}

Which is much more flexible as the fields may hold anything you like! See Enum Constructors for details.

elyashiv Mon 13 Apr 2015

Thanks. I knew about the enum constructors.

Login or Signup to reply.