Enum in Java

Source: Internet
Author: User
public class EnumTest {    enum RadioState {        RADIO_OFF,         /* Radio explictly powered off (eg CFUN=0) */        RADIO_UNAVAILABLE, /* Radio unavailable (eg, resetting or not booted) */        SIM_NOT_READY,     /* Radio is on, but the SIM interface is not ready */        SIM_LOCKED_OR_ABSENT,  /* SIM PIN locked, PUK required, network                               personalization, or SIM absent */        SIM_READY,         /* Radio is on and SIM interface is available */        RUIM_NOT_READY,    /* Radio is on, but the RUIM interface is not ready */        RUIM_READY,        /* Radio is on and the RUIM interface is available */        RUIM_LOCKED_OR_ABSENT, /* RUIM PIN locked, PUK required, network                                  personalization locked, or RUIM absent */        NV_NOT_READY,      /* Radio is on, but the NV interface is not available */        NV_READY;          /* Radio is on and the NV interface is available */        public boolean isOn() /* and available...*/ {            return this == SIM_NOT_READY                    || this == SIM_LOCKED_OR_ABSENT                    || this == SIM_READY                    || this == RUIM_NOT_READY                    || this == RUIM_READY                    || this == RUIM_LOCKED_OR_ABSENT                    || this == NV_NOT_READY                    || this == NV_READY;        }        public boolean isAvailable() {            return this != RADIO_UNAVAILABLE;        }        public boolean isSIMReady() {            return this == SIM_READY;        }        public boolean isRUIMReady() {            return this == RUIM_READY;        }        public boolean isNVReady() {            return this == NV_READY;        }        public boolean isGsm() {            return this == SIM_NOT_READY                    || this == SIM_LOCKED_OR_ABSENT                    || this == SIM_READY;        }        public boolean isCdma() {            return this ==  RUIM_NOT_READY                    || this == RUIM_READY                    || this == RUIM_LOCKED_OR_ABSENT                    || this == NV_NOT_READY                    || this == NV_READY;        }    }public static void main(String[] args) {RadioState mRS = RadioState.RADIO_OFF;System.out.println("RadioState isOn: " + mRS.isOn());System.out.println("RadioState.RADIO_OFF: " + mRS.RADIO_OFF);}}

1. The radiostate enumeration class is a class which cannot be inherited. The enumerated values (radio_off...) are static constants of the radiostate type,

2. The enumeration class is a class. Of course, there are constructors, methods, and data fields in the enumeration type. However, the constructors of enumeration classes are very different:

(1) The constructor is called only when constructing enumeration values.

(2) The constructor can only be private. It is absolutely not allowed to have a public constructor.

3. All enumeration classes inherit the enum method.

 

Reference: http://www.javaeye.com/topic/477731

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.