Matthieu Stombellini
02/02/2020, 4:30 PM// myfile.kt
enum MyEnum {
HELLO, GOODBYE, HEY, GREETINGS
}
fun myFunction() {
doSomethingWith(HELLO) // instead of MyEnum.HELLO
doSomethingElse(GOODBYE) // instead of MyEnum.GOODBYE
}
I'd normally use MyEnum.HELLO
and MyEnum.GOODBYE
but I have a use case where that causes more harm than anything else.
The current workaround I use is to simply declare MyEnum
in a separate file, but that is quite annoying.
(please redirect me to the right channel where I can ask this if there's a better place for this question!)Milan Hruban
02/02/2020, 4:33 PMimport package.MyEnum.*
Mark Murphy
02/02/2020, 4:34 PMimport MyEnum.*
enum class MyEnum {
HELLO, GOODBYE, HEY, GREETINGS
}
fun myFunction() {
println(HELLO)
println(GOODBYE)
}
fun main() {
myFunction()
}
In this case, my code is in the top-level package, so I did not need to put a package qualifier on MyEnum
. In a more traditional case, you would provide the fully-qualified class name for MyEnum
in the import
.Matthieu Stombellini
02/02/2020, 4:34 PM