• 枚举,给枚举赋值


    /**************枚举*****************/
    // 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());//输出枚举元素的值
    //  }
    // }

  • 相关阅读:
    BeautifulSoup
    python爬虫操作excel
    requests
    urllib
    线程的基本用法
    WebView
    播放多媒体文件
    调用摄像头和相册
    03 pycharm编辑默认模板
    测试
  • 原文地址:https://www.cnblogs.com/danmao/p/3825267.html
Copyright © 2020-2023  润新知