zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    对抗杀软高级启发(主动防御)技术
    __readfsdword __readgsqword PEB TEB
    net1 user
    vc 获取windows 网卡信息
    RunPE
    windows crpyt API 实现DES 3DES 3DES_112 加解密
    软件开发图标收藏
    有关windows 网卡信息获取
    BCGPContorBar 静态工程设置详解
    (二)特征匹配
  • 原文地址:https://www.cnblogs.com/zhonghan/p/2232244.html
Copyright © 2011-2022 走看看