• Java Enum


    Enum is a reference type(similar to a class, interface and array), which holds a reference to memory in the heap. Enum class can include other component of a traditional class, such as constructors, member variables and methods.(This is where Java's enum is more powerful than C/C++'s counterparty). Each enum constant can be declared with parameters to be passed to the constructor when it is created.

    Enum默认是public static final的,必须是private constructor,所以不可以instantiate enum,直接用TrafficLight.RED。Enum定义中第一行一定要是RED(30), AMBER(10)...,然后再是private final seconds...。Enum用方法.values()返回数组{RED, AMBER, GREEN}。

    For example:

    enum TrafficLight {

      RED(30),

      AMBER(10),

      GREEN(20);

      private final seconds;

      TrafficLight(int seconds){

        this.seconds=seconds;

      }

      int getSeconds(){

        return this.seconds;

      }

    }

    Enum constants, like RED, are all static. So you can use TrafficLight.RED.

  • 相关阅读:
    vuex 按需动态引入等常用写法
    golang堆栈信息
    fiber框架
    leveldb查看工具
    golang sdk报错
    csdn复制问题
    golang panic打印
    unix socket 抓包
    dlv远程调试
    gitsubmodule使用
  • 原文地址:https://www.cnblogs.com/chayu3/p/3285693.html
Copyright © 2020-2023  润新知