https://kotlinlang.org logo
#announcements
Title
# announcements
m

michaelzinn

08/30/2017, 8:46 AM
wasn’t there a way to use enums like ints or something? What was that called?
k

karelpeeters

08/30/2017, 8:54 AM
You mean calling
.ordinal
on them?
m

michaelzinn

08/30/2017, 8:56 AM
No, I meant you have a function (e.g. in the Android API) that wants an Int and will later return an Int. What you usually do is create a bunch of Int constants and use them, but I think I heard about declaring an enum in such a way that you could pass its values as an Int without calling .ordinal() on them.
Maybe I’m confusing it with another programming language…
k

karelpeeters

08/30/2017, 8:56 AM
There's
IntDef
in Android.
m

michaelzinn

08/30/2017, 8:57 AM
Yeah, guess there’s nothing better than that.
k

karelpeeters

08/30/2017, 8:59 AM
I kind of dislike
IntDef
, it solved a nonexistent problem. You get a bunch of articles like this talking about how enums make your dex files bigger, but meanwhile the play store is is filled with 60MB website wrappers. https://android.jlelse.eu/android-performance-avoid-using-enum-on-android-326be0794dc3
2 Views