我有以下代码:
public enum CpAutoExecCode implements CpAutoErrorCode {
//TODO - List of the execution error codes
//Error code sample
GENERIC_EXECUTION_ERROR(200,"Generic execution error code description"),
MISSING_REQUIRED_FIELD(201,"Required field %s is missing from model : %s");
private final int number;
private final String description;
private CpAutoExecCode(int number,String description) {
this.number = number;
this.description = description;
}
@Override
public int getNumber() {
return number;
}
@Override
public String getDescription() {
return description;
}
}
我想在 %s 中分配必填字段和对象名称。 有谁有简单的方法吗?
最佳答案
您可以将String.format()
与CpAutoExecCode.getDescription()
结合使用:
String formattedMessage = String.format(MISSING_REQUIRED_FIELD.getDescription(),
myMissingField,
myModel);
关于java - 如何操作错误代码枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43974261/