zoukankan      html  css  js  c++  java
  • 枚举类的作用

    目标:枚举类用于做信息标志和信息分类。

      常量做信息标志和分类,虽然也挺好,但是入参不受控制,入参太随性无法严谨。

      枚举采用于做信息标志和信息分类,优雅!

    小结: 建议以后做信息标志和信息分类采用枚举进行!

    package 枚举类的使用;
    
    /**
     * @program: javaDemo01->EumuTest
     * @description: 枚举类的使用
     * @author: 安生
     * @create: 2021-01-15 18:16
     **/
    enum Orientation{
        UP,DOWN,LEFT,RIGHT
    }
    public class EumuTest {
    //    public static final int UP = 1;
    //    public static final int DOWN = 2;
    //    public static final int LEFT = 3;
    //    public static final int RIGHT = 4;
        public static void main(String[] args) {
            //这样做虽然可读性提升了 但是入参不严谨
    //        Demo.movie(RIGHT)
            //使用枚举类
            Demo.movie(Orientation.RIGHT);
    
    
        }
    }
    
    
    //超级玛丽 中有上下左右的按钮
    class Demo{
        //玛丽的移动方法
        public static void movie(Orientation orientation){
            switch (orientation) {
                case UP:
                    System.out.println("玛丽向上!");
                    break;
                case DOWN:
                    System.out.println("玛丽向下!");
                    break;
                case LEFT:
                    System.out.println("玛丽向左!");
                    break;
                case RIGHT:
                    System.out.println("玛丽向右!");
                    break;
            }
    
        }
    }
  • 相关阅读:
    Binary Tree Zigzag Level Order Traversal
    Binary Tree Level Order Traversal
    Symmetric Tree
    Best Time to Buy and Sell Stock II
    Best Time to Buy and Sell Stock
    Triangle
    Populating Next Right Pointers in Each Node II
    Pascal's Triangle II
    Pascal's Triangle
    Populating Next Right Pointers in Each Node
  • 原文地址:https://www.cnblogs.com/bichen-01/p/14283618.html
Copyright © 2011-2022 走看看