Enumeration

This is the back-end small class of the monastery. Each article is shared from

[background introduction] [knowledge analysis] [common problems] [solutions] [coding practice] [extended thinking] [more discussion] [References]

Eight aspects of in-depth analysis of back-end knowledge / skills. This article shares:

【 Enumeration】

1. Background introduction

Enumeration is an important knowledge point. I touched it briefly when I was doing the task before, so I'll introduce it to you this time.

2. Knowledge analysis

Enumeration of value types is a special form of value types,

It is from system Enum inherits and provides an alternate name for the value of the underlying primitive type. An enumeration type has a name, a base type, and a set of fields.

The base type must be a built-in signed (or unsigned) integer type (such as byte, int32, or Uint64).

Fields are static text fields, each of which represents a constant.

The language used assigns each field a specific value of the underlying type.

Enumeration classes in Java can have constructors and implement interfaces, but they cannot inherit any classes. After compilation, they inherit the enumeration classes inside JDK by default.

So the question comes: when do I need to use enumeration?

Enumeration is a good method when we use some fixed constants.

For such "data sets" in the program, their values are stable in the program, and the elements in the "data set" are limited.

For example, seven data elements from Monday to Sunday form a "data set" of a week, and four data elements from spring, summer, autumn and winter form a "data set" of four seasons.

Want to know more?

Look down ↓

PPT:

Video:

Enum enumeration_ Tencent video

Author: yubotao link: https://www.jianshu.com/p/34a8deabfb75 Source: the copyright of Jianshu Jianshu belongs to the author. Please contact the author for authorization and indicate the source for any form of reprint.

For more information, you can join the IT communication group 565734203 to discuss and communicate with you

Here is the skill tree · it Academy: a gathering place for beginners to switch to the Internet

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>