Refer to enums by short name?


#1

Any plans/desire to have enum syntax sort of like Swift, where you don't need to fully qualify the name if the type is known?

  enum class Color { Red, Blue }


  fun paint(c: Color) { }


  paint(.Red)   // for example

Rob


#2

Hi Rob,

You can use a wildcard import. e.g. import foo.Color.*

Note: this doesn’t seem to be possible in the same file that defines the enum, but works elsewhere.

Cheers,
Andrew


#3

Hi Rob,

It’s planned (but not implemented yet) to have short syntax inside when, as in Java, e.g.

  fun paint(c: Color) = when © {
  RED -> …

  GREEN -> …
  }

Also you can use wildcard import, as Andrew has written.


#4

Okay, thanks guys.

Rob