如下所示:
enum color{//枚举 red,green,yellow; } class color1{//模仿枚举 private static int ordinal=-1; private color1(){ ordinal++; } public static final color1 red=new color1(); public static final color1 green=new color1(); public static final color1 yellow=new color1(); public int ordinal(){ return ordinal; } }
在这里我只模仿了获取枚举的下标,大家有兴趣可以模仿一下其他方法
以上这篇java仿枚举实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论