Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This answer is out of date as of March 2011.</strong> </p> <p>Enums can be used on Froyo and up - according to this answer (<a href="https://stackoverflow.com/a/5264861/383414">Why was “Avoid Enums Where You Only Need Ints” removed from Android's performance tips?</a>) from a member of the Android VM team (and <a href="http://elliotth.blogspot.com/2010/09/java-benchmarks.html" rel="nofollow noreferrer">his blog</a>).</p> <hr> <h2>Previous Answer:</h2> <p>The official Android team recommendation is to avoid enums whenever you can avoid it:</p> <blockquote> <p>Enums are very convenient, but unfortunately can be painful when size and speed matter. For example, this:</p> <pre><code>public enum Shrubbery { GROUND, CRAWLING, HANGING } </code></pre> <p>adds 740 bytes to your .dex file compared to the equivalent class with three public static final ints. On first use, the class initializer invokes the method on objects representing each of the enumerated values. Each object gets its own static field, and the full set is stored in an array (a static field called "$VALUES"). That's a lot of code and data, just for three integers. Additionally, this:</p> <pre><code>Shrubbery shrub = Shrubbery.GROUND; </code></pre> <p>causes a static field lookup. If "GROUND" were a static final int, the compiler would treat it as a known constant and inline it.</p> </blockquote> <p>Source: <a href="http://developer.android.com/guide/practices/design/performance.html#avoid_enums" rel="nofollow noreferrer">Avoid Enums Where You Only Need Ints</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload