---
# System prepended metadata

title: 指定 enum 類型
tags: [實作相關]

---

指定 enum 類型
===

```java=
public enum EnumTest {
    NAME_ONE("Name 1"),
    NAME_TWO("Name 2");

    private final String val;

    EnumTest(final String val) {
        this.val = val;
    }

    public String getVal() {
        return val;
    }
}

```
呼叫：
```java=
public class Test {
    public static void main (String args[]){
        System.out.println(EnumTest.NAME_ONE.getVal());
        System.out.println(EnumTest.NAME_TWO.getVal());
    }
}
```
## Ref.
[Best way to create enum of strings?](https://stackoverflow.com/questions/3978654/best-way-to-create-enum-of-strings)

###### tags: `實作相關`