C # Idioms:enum or enum class (enum Class)
Marshine
(Original composition format: http://www.marshine.com)
Reversion:2004/5/28
Modification Note: Thanks to the CLS compatibility issue mentioned by Ninputer, while modifying the Equals rewrite not
Reference 55049192This explains why an enumeration class cannot be inherited: it has inherited the parent enum class, and its parent implements the serializable interface, which means that all enum classes implement serializationThe Enum class also
Public Abstract classEnumextendsEnum>ImplementsComparable, Serializable {Private FinalString name; //Current enumeration constant name Public FinalString name () {returnname; } Private Final intordinal; //Current enumeration constant
Sometimes, the value of a variable is only within a finite set.For example: the size of the pizza is only small, medium, large and oversized in these four sizes. Of course, these dimensions can be encoded as 1, 2, 3, 4, or S, M, L, X, respectively.
I. Grammar1. Enum is all called enumeration, Chinese is commonly known as enumeration class, learn C + + and other languages of the people, should be to it knows. In the Java language Specification, however, it was introduced in the JDK version 5
Enum Enum class
1.values ()Description: The values () method returns a collection of enumeration classes that do not exist in the Enum class and are added by the compiler dynamically.
2.valueOf ()Description: valueof () returns an object of the
Learn from teacher Wang Enumeration (iii): Enumeration APITeacher: Wang Shaohua QQ Group No.: 483773664First, enumerate the class APIThe enumeration classes declared in Java are children of the Java.lang.Enum class that inherit all the methods of
1. Use an extension method to use an enumeration value for the Description property value Public Static classenumextenstion{ Public Static stringGetdescriptionname ( ThisEnum Enumvalue) {Object[] attr =Enumvalue.gettype (). GetField
With the effective Java this book to see more and more, found in peacetime use of Java made a lot of obvious mistakes, they usually know a little but the lack of use is also more and more.As for enumeration classes, the suggestion in the book is to
There's something new in the enumeration class in Kotlin: The constant of an enumeration class can be seen as an anonymous class with the same name.Since it is a class, it can be associated with a methodCheck the code of the official websiteIf you
Enumeration definition:An enum is a data type in a computer programming language. Enumeration types: In real-world problems, some variables are scoped to a limited range . For example, there are only seven days in one weeks, 12 months in a year, six
This article is taken from the csdn forum post
Q: Question
The tostring () method of the enum class can be different from several parameters, such:Enum. tostring ("D ");Enum. tostring ("N ");Enum. tostring ("G ");Enum. tostring ("F ");What do
The enumeration classes are new after Java 5, can be used to encapsulate constants, and can also provide some methods for the use of constants.Defines the syntax for an enumeration class: Public enum enumname{ //must be placed on the
Unlike an unscoped enumeration, a scoped enumeration are not implicitly convertible to its integer value. You need to explicitly convert it to an integer using a cast:Std::cout ::type> (A) Want to encapsulate the logic into a function
An enum class has been added to the JDK1.5 that can be used to map to database tables. And it's very convenient to implement.
Here's an example:
Development environment:
JDK 1.6 U2
Eclipse 3.3
There is a table in the database: Useruser
It has
This model is built in models, in which the method of obtaining an enumeration class is writtenDo not pirated, reproduced please add the source Http://blog.csdn.net/yanlintao1Class Student extends zend_db_table{protected $_name = ' student
I. Overview An enum, called enumeration, is a new feature introduced in JDK 1.5 and is housed in a Java.lang package. creating an enumeration type to use the enum keyword implies that the type created is a subclass of the Java.lang.Enum class
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.