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 }
  • 相关阅读:
    [这不是Windows Phone 7]FitnessTrackerPlus(健身)三.登录及MD5加密
    [Windows Phone 7璀璨]北漂1.0在线歌词播放器三.歌词下载
    [Windows Phone 7璀璨]北漂1.0在线歌词播放器四.独立储存空间歌词的读取(完结)
    [原创]Xcode 4.6 安装 Boost 1.53.0
    [学习笔记]Silverlight4 RIA 开发全程解析[项目全程记录]第零章项目简介
    [笔记]Cocoa训练营cocos2d游戏编程篇动画
    [学习笔记]Silverlight4 RIA 开发全程解析[项目全程记录]第一章FitnessTrackerPlus应用程序概述
    [笔记]Cocoa训练营内存管理篇
    Android_相关路径
    Dynamics AX2009 Report step by step
  • 原文地址:https://www.cnblogs.com/zhonghan/p/2232244.html
Copyright © 2011-2022 走看看