R8, Android's optimizer, can replace calls to enum's ordinal() and name() methods with compile-time constants when the enum constant is known statically. When ordinal() is called on a fixed constant, R8 substitutes the integer value directly, enabling further optimizations like switch branch elimination. Similarly, name() calls on known constants are replaced with string literals at no extra cost since the string already exists as the constant's identifier. These small optimizations compound with other R8 passes to produce significant bytecode reductions.

6m read timeFrom jakewharton.com
Post cover image
Table of contents
OrdinalName
2 Impressions