https://kotlinlang.org logo
#android
Title
# android
j

jw

04/20/2018, 1:19 PM
and if it somehow does become a problem, congratulations! you are facebook and rolling in money and you can retire and hire 300 other Android devs to fix the problem and go live on your private island
👍 9
🧌 8
😂 1
💯 1
🤣 9
g

gildor

04/20/2018, 2:36 PM
@adam-mcneilly just for fun grep unpacked Facebook APK and found 74 enum declarations 😬
😂 4
j

jw

04/20/2018, 2:38 PM
I suspect they aggressively optimize them out. At Google we have something called
@SimpleEnum
which requires that the enum can be optimized into an int and fails the build if it can't.
g

gildor

04/20/2018, 2:39 PM
Is that optimized by proguard/r8?
j

jw

04/20/2018, 2:39 PM
Yes
g

gildor

04/20/2018, 2:40 PM
So is it just enum without fields and methods marked as SimpleEnum?
j

jw

04/20/2018, 2:41 PM
Yes. The key is just that you are prevented from causing de-optimization without explicitly removing the annotation.
g

gildor

04/20/2018, 2:41 PM
Such approach is much better than
@IntDef
imo Thanks for information
j

jw

04/20/2018, 2:42 PM
I don't disagree!
👍 4
l

louiscad

04/20/2018, 4:52 PM
@jw How can I use
@SimpleEnum
in my projects? Does proguard/r8 handle inlining them to int even when there are extension functions/properties for the enum?
j

jw

04/20/2018, 4:53 PM
You cannot. Extensions are static methods so they don't affect the enum.
Just write normal enums. 90% of them will optimize away anyway and you don't have to care.