-
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);
}
}