0

I have to implement some classes with functions. These functions have to return some errors codes, I usually use to declare a public enum with the errors codes and that work for me (for example in c#) but I had read that enums are not so good in Android (performance), so what do you think about this code?

public class myClass_1
{
public final class myErrorCodes
{
    public static final int ERROR_1 = 0x01;
    public static final int ERROR_2 = 0x02;
    public static final int ERROR_3 = 0x03;
    public static final int ERROR_4 = 0x04;
    public static final int ERROR_5 = 0x05;
    public static final int ERROR_6 = 0x06;
}

public int Function_1(int a,int b)
{
    // do something here...

    return myErrorCodes.ERROR_1;
}
}
skabo
  • 71
  • 9
  • 4
    Not so sure Enums are bad (anymore), http://stackoverflow.com/questions/5143256/why-was-avoid-enums-where-you-only-need-ints-removed-from-androids-performanc – Joachim Isaksson Feb 06 '12 at 12:50

2 Answers2

4

The enum performance warning was removed from the documentation.

See: Why was "Avoid Enums Where You Only Need Ints" removed from Android's performance tips?

Community
  • 1
  • 1
Rob Pridham
  • 4,780
  • 1
  • 26
  • 38
0

There is not any problems with enums now. So, you can use it if you want.

Code with ints will work slightly faster - but you will neve see it :)

Community
  • 1
  • 1
Jin35
  • 8,602
  • 3
  • 32
  • 52