Java enum use case

Source: Internet
Author: User

Enum Usage:

Use Case 1:

 Public enumENUM1 {//Yahoo Headline News RSS seedsYahoo_top_stories ("Http://rss.news.yahoo.com/rss/topstories"),        //CBS Headline News RSS seedsCbs_top_stories ("Http://feeds.cbsnews.com/CBSNewsMain?format=xml"),        //Los Angeles Times Headline News RSS seedsLatimes_top_stories ("Http://feeds.latimes.com/latimes/news?format=xml"); //enumerates the properties of an object's RSS address    PrivateString Rss_url; //Enumerating Object Constructors    Privatenewsrssfeedenum (String rss) { This. Rss_url =RSS; }            //enumeration objects How to get an RSS address     PublicString Getrssurl () {return  This. Rss_url; }}

Use Case 2:

 Public enum Enum2 {    //  Yahoo Headline news RSS seed     yahoo_top_stories,        //CBS Headline News RSS seed     cbs_top_stories,     //  Los Angeles Times Headline News RSS seed     latimes _top_stories;      Public String}



However, there are several places to note when using Enum:
The enum type does not support the construction of the public and protected modifiers, so constructors must be private or friendly. Because of this, the enumeration object cannot be initialized in the program by directly invoking its constructor method.
When defining an enum type, if it is a simple type, then the last enumeration value is not followed by any symbol, but if there is a custom method, then the last enumeration value will be separated from the following code with a semicolon '; ' Separated, cannot use commas or spaces.
Because the value of the enum type is actually represented by the runtime construction object, each virtual machine constructs a synonym enumeration object in the cluster environment. Use switch as much as possible to determine

Java enum use case

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.