[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC: help me with Java enums please
From: |
Akim Demaille |
Subject: |
Re: RFC: help me with Java enums please |
Date: |
Sun, 5 Apr 2020 08:47:20 +0200 |
Hi Paul!
> Le 4 avr. 2020 à 19:34, Paul Eggert <address@hidden> a écrit :
>
> On 4/4/20 12:12 AM, Akim Demaille wrote:
>> The JVMs are known to be quite good at optimizing, but I have no idea
>> whether this abstraction will be zero-cost or not.
>
> Although I'm no Java expert,
Thanks for accepting taking a trip in Javaland :)
> a quick bit of Googling suggests that JVMs don't deal with enums quite as
> efficently as they do with ints. See, for example:
>
> https://developer.android.com/topic/performance/reduce-apk-size
>
> which says: "Avoid enumerations. A single enum can add about 1.0 to 1.4 KB of
> size to your app's classes.dex file. These additions can quickly accumulate
> for complex systems or shared libraries. If possible, consider using the
> @IntDef annotation and code shrinking to strip enumerations out and convert
> them to integers. This type conversion preserves all of the type safety
> benefits of enums."
This sounds rather convincing. However,
> Have you considered using @IntDef instead?
AFAICT @IntDef is Android only, it's not part of standard Java.
https://developer.android.com/reference/kotlin/androidx/annotation/IntDef
Cheers!