Given the cost of using enums (vs IntDef), but not...
# android
s
Given the cost of using enums (vs IntDef), but not wanting to give up on the convenience they add - I was thinking it should be possible to have the compiler (or a build plugin) do the conversion for us (at least for “simple” enums with no methods/inheritance etc), so that we can get the best of both worlds. Does something like this already exist?
I know this isn’t Android specific, but the enum problem seems to be more severe for Android applications
j
ProGuard has done this forever. R8 also does this now. Also the cost has been dramatically overstated as a problem. It's not a problem.
s
huh, that’s good to know! I’ve seen it brought up again and again and figured it must still be a problem if people keep talking about it 😅 I wonder what’s the limit of ProGuard/R8 when it comes to “un-enuming”. I’m assuming there’s a point where it would give up and leave it as an enum (non-empty constructor, overridden methods, etc..?)
j
All of those, yes. Using it as a synchronized lock, implementing an interface, etc.
s
ah, so it only converts the most basic/straightforward uses of enums?
j
Yes. Use it like a class, pay for a class. Use it like an int, it'll only cost an int.
s
Awesome, thanks for all the info 🙂