---
title: "enum 的 name 是如何传进去的呢？"
author: "zwhc"
date: "2011-11-08T17:48:22Z"
tags: []
categories: ["编程语言"]
slug: "enum-name"
draft: false
lastmod: "2011-11-08T17:57:44Z"
id: 1243598
url: "https://zwhc.iteye.com/blog/1243598"
---

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