枚举,给枚举赋值
/**************枚舉*****************/
//?public enum Colors{
//??Red,Yellow,Blue,Black,White
//?}
//?public static void main(String[] args) {
//??Colors c = Colors.Yellow;
//??System.out.println(c);//輸出枚舉
//??System.out.println(c.ordinal());//輸出枚舉對應的序號(第一個枚舉元素是0,后面的依次+1)
//??
//??//將字符串轉換為枚舉
//??Colors c2 = Enum.valueOf(Colors.class, "Blue");
//??if(c2 == Colors.Blue){
//???System.out.println("轉換成功!");
//??}
//??//枚舉在switch中的使用
//??switch (c2) {
//???case Red:
//????System.out.println("紅色!");
//????break;?
//???case Yellow:
//????System.out.println("黃色!");
//????break;?
//???case Blue:
//????System.out.println("藍色!");
//????break;?
//???case Black:
//????System.out.println("黑色!");
//????break;
//???case White:
//????System.out.println("白色!");
//????break;
//???default:
//????break;
//??}
//?}
?
?/**************給枚舉賦值***************/
//?public enum Colors{
//??Red(1),Yellow(3),Blue(5);
//??private int _value;
//??Colors(int value){
//???_value=value;
//??}
//??int getValue(){
//???return _value;
//??}
//?}
//?public static void main(String[] args) {
//??for (Colors c : Colors.values()) {
//???System.out.println(c);//輸出枚舉元素
//???System.out.println(c.getValue());//輸出枚舉元素的值
//??}
//?}
轉載于:https://www.cnblogs.com/danmao/p/3825267.html
總結
- 上一篇: 在wpf中运行EXE文件
- 下一篇: 做鼻中隔隆鼻多少钱?