什么是枚舉,它們?yōu)槭裁从杏茫拷裉煳覟g覽了一下這個網(wǎng)站上的一些問題,我發(fā)現(xiàn)其中提到了enum 用于單例模式關(guān)于所謂的線程安全的好處,這樣的解決方案。我從來沒有用過enumS和我用Java編程已經(jīng)有兩年多了。顯然他們改變了很多。現(xiàn)在,他們甚至在自己的內(nèi)部完全支持OOP?,F(xiàn)在,為什么和為什么我應(yīng)該在日常編程中使用枚舉?
3 回答

慕絲7291255
TA貢獻1859條經(jīng)驗 獲得超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);