package com.wql.test;

public class Test6 {

public static void main(String[] args) {

test1(ErrorType.ERROR_2);

}

public static void test1(ErrorType type){

switch(type){

case ERROR_1:

System.out.println("参数type="+type+",value="+type.getValue()+",msg="+type.getMsg());

break;

case ERROR_2:

System.out.println("参数type="+type+",value="+type.getValue()+",msg="+type.getMsg());

break;

case ERROR_3:

System.out.println("参数type="+type+",value="+type.getValue()+",msg="+type.getMsg());

break;

}

}

}

enum ErrorType{

ERROR_1(1,"一错误"),

ERROR_2(2,"二错误"),

ERROR_3(3,"三错误");

private int value;//错误代码

private String msg;//错误描述

//注意!构造方法是私有的

private ErrorType(int value,String msg){

this.value = value;

this.msg = msg;

}

public int getValue() {

return value;

}

public void setValue(int value) {

this.value = value;

}

public String getMsg() {

return msg;

}

public void setMsg(String msg) {

this.msg = msg;

}

}

 为了让学习变得轻松、高效,今天给大家免费分享一套Java教学资源。帮助大家在成为Java架构师的道路上披荆斩棘。需要资料的欢迎加入学习交流群:9285,05736

java enum枚举使用例子

相关文章:

  • 2022-12-23
  • 2022-01-21
  • 2021-11-30
  • 2022-12-23
  • 2022-01-29
  • 2021-11-25
  • 2021-08-06
猜你喜欢
  • 2022-12-23
  • 2021-07-28
  • 2021-06-12
  • 2021-10-23
  • 2023-03-18
  • 2022-01-17
相关资源
相似解决方案