1.数字
Integer type = 1;
switch (type) {
case 1:
System.out.println(1);
break;
case 2:
System.out.println(2);
break;
default:
System.out.println("null");
}
System.out.println("null");
}
2.枚举
public enum UserTypeEnum {
one(1, "1"),
two(2, "2"),
three(3, "3");
private long type;
private String name;
UserTypeEnum(int type, String name) {
this.type = type;
this.name = name;
}
public long getType() {
return type;
}
public String getName() {
return name;
}
}
UserTypeEnum userTypeEnum = null;
switch (userTypeEnum) {
case one:
System.out.println(1);
break;
case two:
System.out.println(2);
break;
case three:
System.out.println(2);
break;
default:
System.out.println("null");
}
3.字符串
String typeStr = "type1";
switch (typeStr) {
case "type1":
System.out.println(1);
break;
case "type2":
System.out.println(2);
break;
default:
System.out.println("null");
}