定义字符串类型常量
public class ConstantUtils {
/**
* 分隔符 中横线"-"
*/
public static final String HYPHEN = "-";
}
定义枚举类型常量
public class ConstantUtils {
/**
* 操作类型枚举类
*/
public enum OperateType {
ADD("add", "添加"),
DELETE("delete", "删除"),
UPDATE("update", "更新"),
;
private String value;
private String text;
OperateType(String value, String text) {
this.value = value;
this.text = text;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
}
使用常量
System.out.println(ConstantUtils.HYPHEN);
System.out.println(ConstantUtils.OperateType.ADD.getValue());
System.out.println(ConstantUtils.OperateType.ADD.getText());