java中枚举在游戏开发中作用

来源:互联网 发布:js实现数据绑定 编辑:程序博客网 时间:2024/06/05 11:40

这里写图片描述


package com.hai.tao;public enum Color {    REDD("红色", 11), GREENN("绿色", 22), BLUEE("白色", 33), YELLOO("黄色", 44);    private String name;    private int index;    private Color(String name, int index) {        this.name = name;        this.index = index;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public int getIndex() {        return index;    }    public void setIndex(int index) {        this.index = index;    }}

package com.hai.tao;public class test {    /**     * @param args     */    public static void main(String[] args) {        // 遍历所有的枚举        for (Color color : Color.values()) {            System.out.println(color + "       " + color.getName() + "      " + color.getIndex());        }    }}


这里写图片描述


java中的枚举在多人在线游戏后台开发中扮演什么角色昵?


回答是,通常用于消息处理器类的注册


这里写图片描述



FR:徐海涛(Hunk Xu)