此代码可以完整的演示玫举的使用的快捷性, 玫举类

package com.anydata.obd.gis;

public enum Code {

    MODULE_PWR_ON_E(3000, "开机"),

    MODULE_PWR_OFF_E(3001, "关机"),

    CURRENT_INFO_CODE_E(3002, "当前状态信息"),

    INIT_ACT_DEV_EVNT_E(3003, "车辆信息更新报警"),

    HEARTBEAT_SHORT_E(3004, "位置报告(短)"),

    HEARTBEAT_LONG_E(3005, "位置报告(长)"),

    GEOFENCE_CODE_E(3006, "围栏报警"),

    RESERVED2(3007, ""),

    ENGINE_CHECK_LIGHT_E(3008, "引擎故意灯报警"),

    DTC_EVENT_E(3009, "车辆故障码报警"),

    SPEED_CODE_E(3010, "超速报告"),

    HIGH_RPM_CODE_E(3011, "超转速报警"),

    BATT_ALERT_CODE_E(3012, "电池低压报警"),

    UNAUTH_MOVE_E(3013, "非法移动报警"),

    FUEL_LEVEL_LOW_E(3014, "油量低报警"),

    IGN_ON_CODE_E(3015, "引擎发动"),

    IGN_OFF_CODE_E(3016, "引擎熄火"),

    COOLANT_TEMP_E(3017, "冷却液高温报警"),

    IDLING_E(3018, "空转报警"),

    FUEL_LEVEL_CHANGE_E(3019, "油量变动过快报警"),

    ONE_MPH_CROSS_E(3020, "起步停车报警"),

    RESERVED3(3021, ""),

    RESERVED1(3022, ""),

    RESERVED4(3023, ""),

    HARD_ACCEL_E(3024, "急启动事件"),

    HARD_CORNERING_E(3025, "急转弯事件"),

    HARD_BREAKING_E(3026, "急刹车事件"),

    RESERVED5(3027, "");

    private int code;
    private String description;

    Code(final int code, final String _des) {
        this.code = code;
        this.description = _des;
    }

    public int getCode() {
        return this.code;
    }

    public String getDescription() {
        return this.description;
    }

    // 普通方法
    public static String getDescription(int _code) {
        for (Code c : Code.values()) {
            if (c.getCode() == _code) {
                return c.description;
            }
        }
        return null;
    }

}

使用方法, 得到中文描述

String description= Code.getDescription(code);

一点问题就是使用了for,可能会让效率比较低下..