• 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 }
  • 相关阅读:
    WPF and SL RadioButtonList Tip
    Prism V2之旅(1)
    wpf开发常见问题(1)
    (转)英语学习者的十句经典名言
    json格式化,统一格式?,前端与后端的矛盾
    路由器默认地址跟帐号密码
    ASP操作XML数据小结
    系统封装工具和常用软件下载(2009年10月更新的)
    全国邮编、区号数据、IP数据库
    Linux 包管理速查表
  • 原文地址:https://www.cnblogs.com/zhonghan/p/2232244.html
Copyright © 2020-2023  润新知