什么是枚举,它们为什么有用?今天我浏览了一下这个网站上的一些问题,我发现其中提到了enum 用于单例模式关于所谓的线程安全的好处,这样的解决方案。我从来没有用过enumS和我用Java编程已经有两年多了。显然他们改变了很多。现在,他们甚至在自己的内部完全支持OOP。现在,为什么和为什么我应该在日常编程中使用枚举?
3 回答

慕丝7291255
TA贡献1859条经验 获得超6个赞
/** Counts number of foobangs. * @param type Type of foobangs to count. Can be 1=green foobangs, * 2=wrinkled foobangs, 3=sweet foobangs, 0=all types. * @return number of foobangs of type */public int countFoobangs(int type)
/** Types of foobangs. */public enum FB_TYPE { GREEN, WRINKLED, SWEET, /** special type for all types combined */ ALL;}/** Counts number of foobangs. * @param type Type of foobangs to count * @return number of foobangs of type */public int countFoobangs(FB_TYPE type)
int sweetFoobangCount = countFoobangs(3);
int sweetFoobangCount = countFoobangs(FB_TYPE.SWEET);
int sweetFoobangCount = countFoobangs(99);
添加回答
举报
0/150
提交
取消