首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

enum 的 name 是怎么传进去的呢

2012-10-06 
enum 的 name 是如何传进去的呢?enum 的 name 是如何传进去的呢?public enum Enum01 {NANOSECONDS(0), MIC

enum 的 name 是如何传进去的呢?
enum 的 name 是如何传进去的呢?

public enum Enum01 {
NANOSECONDS(0), MICROSECONDS(1), MILLISECONDS(2), SECONDS(3);

    /** the index of this unit */
    private final int index;

    /** Internal constructor */
    Enum01(int index) {
        this.index = index;
    }

}

Enum01 en = Enum01.MICROSECONDS;
l.info(en.name());

--------------------------
输出:
MICROSECONDS

enum 的 name 是如何传进去的呢?很有些奇怪。
不过,这样用起来很爽啊。


唔,刚才查了一下,可以参考一下这个。
http://www.iteye.com/topic/6556

热点排行