[英]Android Java: is this a good way instead enums?
我必须实现一些带有函数的类。 这些函数必须返回一些错误代码,我通常使用该错误代码声明一个公共枚举,并且该枚举对我有用(例如,在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;
}
}
枚举性能警告已从文档中删除。
现在枚举没有任何问题。 因此,您可以根据需要使用它。
带int的代码会稍微快一些-但您一定会看到它:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.