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?
StavFX
08/10/2020, 6:49 PM
I know this isn’t Android specific, but the enum problem seems to be more severe for Android applications
j
jw
08/10/2020, 6:59 PM
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
StavFX
08/10/2020, 7:13 PM
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
jw
08/10/2020, 7:45 PM
All of those, yes. Using it as a synchronized lock, implementing an interface, etc.
s
StavFX
08/10/2020, 7:58 PM
ah, so it only converts the most basic/straightforward uses of enums?
j
jw
08/10/2020, 9:37 PM
Yes. Use it like a class, pay for a class. Use it like an int, it'll only cost an int.