• java enum


     1 package com.karl.test;
     2 
     3 public class TestEnum {
     4     
     5     public enum ColorSelect{
     6         red,green,yellow,blue;
     7     }
     8 
     9     public enum Season{
    10         spring,summer,fall, winter;
    11         private final static String location = "Phoenix";
    12         
    13         public static Season getBest(){
    14             if(location.endsWith("Phoenix"))
    15                 return winter;
    16             else
    17                 return summer;
    18         }
    19     }
    20     
    21     public enum Temp{
    22         absoluteZero(-459), freezing(32), boiling(212), paperBurns(451);
    23         private final int value;
    24         public int getValue(){
    25             return value;
    26         }
    27         Temp(int value){
    28             this.value = value;
    29         }
    30     }
    31     
    32     
    33     public static void main(String[] args) {
    34         ColorSelect m = ColorSelect.blue;
    35         switch(m){
    36         case red:
    37             System.out.println("color is red");
    38             break;
    39         case green:
    40             System.out.println("color is green");
    41             break;
    42         case yellow:
    43             System.out.println("color is yellow");
    44             break;
    45         case blue:
    46             System.out.println("color is blue");
    47             break;
    48         }
    49         
    50         for(ColorSelect c : ColorSelect.values()){
    51             System.out.println(c);
    52         }
    53         
    54         System.out.println("total " + ColorSelect.values().length + " in ColorSelect.");
    55         
    56         System.out.println("the position of blue in ColorSelect is " + ColorSelect.blue.ordinal());
    57         
    58         System.out.println("compare red to green " + ColorSelect.red.compareTo(ColorSelect.green));
    59         
    60         System.out.println("Season.getBest()= " + Season.getBest());
    61         
    62         for (Temp t : Temp.values()) {
    63             System.out.println("The value of t is " + t.getValue());
    64         }
    65 
    66     }
    67 }
  • 相关阅读:
    前端vscode比较好用的保存自动格式化settings.json配置
    jvm 调优
    ElasticSearch CPU和内存占用高的优化记录
    nginx 安装部署
    Windows 下Redis的部署 及key 过期事件
    Docker 部署应用过程记录
    实现鼠标悬停,div勾画div边框的动画
    html+jquery实现简单图片裁剪
    css+jquery 实现图片局部放大预览
    flex 布局 实现电商网页菜单的多级分类展示
  • 原文地址:https://www.cnblogs.com/zhonghan/p/2232244.html
Copyright © 2020-2023  润新知