本文共 988 字,大约阅读时间需要 3 分钟。
package example.testForJava;public enum ResponseCodeEnum { SUCCESS(1,"success"), FAIL(-1,"fail"), NOT_FOUND(404,"not found"); private Integer code; private String message; ResponseCodeEnum(Integer code,String message){ this.code=code; this.message=message; } public Integer getCode() { return code; } public void setCode(Integer code) { this.code = code; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; }}
package example.testForJava;public class CodeEnumTest { public static void main(String[] args) { String message=ResponseCodeEnum.SUCCESS.getMessage(); System.out.println(message); String message2=ResponseCodeEnum.FAIL.getMessage(); System.out.println(message2); Integer integer=ResponseCodeEnum.SUCCESS.getCode(); System.out.println(integer); }}
转载地址:http://xqrwi.baihongyu.com/