//定义处
public enum TestItem
{
CPU,
MEMORY,
PROCESS,
BATTERY,
THREEG
}
//使用处
String TAG = "FlowWindow";
for(TestItem testItem:TestItem.values())
{
Log.i(TAG, "----------testitem--------------------- " + testItem.ordinal());
}
//log结果
02-23 14:43:34.730: INFO/FlowWindow(1706): ----------testitem--------------------- 0
02-23 14:43:34.730: INFO/FlowWindow(1706): ----------testitem--------------------- 1
02-23 14:43:34.730: INFO/FlowWindow(1706): ----------testitem--------------------- 2
02-23 14:43:34.730: INFO/FlowWindow(1706): ----------testitem--------------------- 3
02-23 14:43:34.730: INFO/FlowWindow(1706): ----------testitem--------------------- 4
java中枚举类型被看作类,和C中的枚举类型不同,开始用C中枚举类型去看待果然傻了。
本文详细介绍了Java中枚举类型的特性和用法,通过实例展示了如何遍历枚举成员并获取其序号,并对比了Java枚举与C语言中枚举的区别。
3272

被折叠的 条评论
为什么被折叠?



