指定 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: `實作相關`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up