-
StackOverflow 文件
-
Java Language 教程
-
枚號以數字開頭
-
名字在開頭的列舉
public enum BookCode {
_10A("Simon Haykin", "Communication System"),
_42B("Stefan Hakins", "A Brief History of Time"),
E1("Sedra Smith", "Electronics Circuits");
private String author;
private String title;
BookCode(String author, String title) {
this.author = author;
this.title = title;
}
public String getName() {
String name = name();
if (name.charAt(0) == '_') {
name = name.substring(1, name.length());
}
return name;
}
public static BookCode of(String code) {
if (Character.isDigit(code.charAt(0))) {
code = "_" + code;
}
return BookCode.valueOf(code);
}
}