Operations on int occur many times faster than operations on enum.
Judge for yourself. Each time you create a enum you create as a minimum:
1) Class-loader for it.
2) You keep this object in memory.
3) Since enum is static anonymous class - it will always hang in your memory (sometimes even after you close the application.)
With regard to the Service
. In this class, the flags are mainly used for comparisons and return the result to the class above (ContextWrapper
). But basically, if you dig into the bowels of Android SDK you will discover for yourself that almost all these flags are used to bynary shift operations.
Even in Java use a binary shift operations in JDK :
/**
* Max capacity for a HashMap. Must be a power of two >= MINIMUM_CAPACITY.
*/
private static final int MAXIMUM_CAPACITY = 1 << 30;
Also you can look to Window class in Android SDK
/**
* Set the container for this window. If not set, the DecorWindow
* operates as a top-level window; otherwise, it negotiates with the
* container to display itself appropriately.
*
* @param container The desired containing Window.
*/
public void setContainer(Window container) {
mContainer = container;
if (container != null) {
// Embedded screens never have a title.
mFeatures |= 1<<FEATURE_NO_TITLE;
mLocalFeatures |= 1<<FEATURE_NO_TITLE;
container.mHasChildren = true;
}
}
/** The default features enabled */
@SuppressWarnings({"PointlessBitwiseExpression"})
protected static final int DEFAULT_FEATURES = (1 << FEATURE_OPTIONS_PANEL) |
(1 << FEATURE_CONTEXT_MENU);
So reasons is two(at least):