Java枚举String字符串

  • 定义枚举
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public enum Sex {
MALE("男"), //男
FEMALE("女"), //女

private final String sex;

private Sex(final String sex) {
this.sex = sex;
}

@Override
public String toString() {
return sex;
}
}
  • 访问枚举
1
String sexName = Sex.MALE.toString();

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :