我必须实现一些带有函数的类。这些函数必须返回一些错误代码,我通常用它来声明一个带有错误代码的公共(public)枚举,并且该枚举对我有用(例如在 C# 中),但我读到枚举在 Android 中不太好(性能),那又怎样呢?你想一下这段代码吗?
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;
}
}
最佳答案
枚举性能警告已从文档中删除。
参见:Why was "Avoid Enums Where You Only Need Ints" removed from Android's performance tips?
关于java - 安卓 Java : is this a good way instead enums?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9160342/