一、第一种常量类定义
定义
public class ConstClass {
public static String AHS= "xxx";
public interface AuditState{
String AUDIT_ZERO = "0";
String AUDIT_ONE= "1";
String AUDIT_TWO= "2";
}
}
使用
public static void main(String[] args) {
String ahs= ConstClass.AHS;
String state= ConstClass.AuditState.AUDIT_ZERO;
}
二、第二种常量类定义
定义
public interface NameCodePrincipal {
String getName();
int getCode();
}
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
@Getter
public enum AuditState implements NameCodePrincipal {
AUDIT_ZERO("待审核", 0),
AUDIT_ONE("审核通过", 1),
AUDIT_TWO("审核失败", 2);
private final String name;
private final int code;
AuditState(String name, int code) {
this.name = name;
this.code = code;
}
}
使用
public interface NameCodePrincipal {
int code = AuditState.AUDIT_ZERO.getCode();
}