as a parameter, and the value of the parameter is the value of the variable name.3. Variable name (variable name corresponding value) {Static code block}//except 2, the enumeration class also defines an abstract method, and the code block after the variable name corresponds to an anonymous inner class that implements the abstract method. As follows: Variable type variable name =new
() ; } } Public Connection getconnection () { return Connection; }}The Run method of the custom line thread is modified to: public void Run () { System.out.println (singleton.connectionfactory. Getconnection (). Hashcode ()); }
103201006910320100691032010069
5. Perfect using Enum enumeration to implement Singleton modeThe preceding section exposes enumerated classes, violat
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 courses per week in a class, and so on. If these quantities are described as integers, the character type or other types are obviously inappropriate. For this r
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 first row of member 1 (A, B ... ), member 2 (A, B ... ), member 3 (A, b ...). )........; //a,b can not P
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 and stored in the Java.lang package. In the Java version of the
, and fields to the enumeration type. Of course, the constructor is called only when constructing enumeration constants. A facet is an example:public enum Size{small ("S"), MEDIUM ("M"), LARGE ("L"), Extra_large ("XL");p rivate String abbreviation;private Size ( String abbreviation) {this.abbreviation=abbreviation;} Public String getabbreviation () {return abbreviation;}}All enum types are subclasses of the
Long time no contact enumeration class, almost forget, today take a moment to summarize it. To be honest, enumerating classes can really make a lot of sense for us.Description: Enum class It contracts a scope, it can be understood that only a fixed number of objects can be generated to call the outside world, so the constructor method in the enumeration
class variable.
If necessary, you can provide some static methods that allow other programs to get an instance of the match based on the parameters.
Using an enumeration class can make your program more robust and avoid the randomness of creating objects.
However, it is cumbersome to implement enumerations by defining classes to implement them, and Java
In Java, serialization of an enum type differs from the serialization of other object types, to see what is different today. Let's look at how the enum we defined in Java is going to look like after being compiled.
Java code:
Java
attributes of the class type, such as construction method, member variable, member method, etc. This is the enumeration type not only has to distinguish the different categories of functions, and even can add their own methods for different types, of course, to implement an interface before the line, and implement some of these types of public methods, so the enumeration type to represent different types, it is more flexible than with different stati
Enum class Enum is introduced by JDK1.5, and is preceded by a public static final int Enum_value instead of an enumeration class. Enum class Enum is a special
intSeason_winter=4; the the Enumerate class instances: the Public enumseasonenum{ the //4 enumerated instances in the first row - Spring,summer,fall,winter; in } the the //Test Class About Public classenumtest{ the Public voidjudge (Seasonenum s) { the //the expression in the switch statement can be an enumeration class the Switch(s)
1, the enumeration class is also a class, you can have attributes, and so on:public enum Seasonenum{spring,summer,fall,winter;}This is not the other attribute.Package Com.creditharmony.adapter.testcase.test;public class Enumtest {public void judge (Seasonenum s) {switch (s) {case SPRING:System.out.println ("Spring"); B
This error occurs: A class, interface, or enum hint is required, generally in two cases:1. The code is incorrectly written;2. There is a problem with the Encoder selection encoding format. ( mainly in non-Notepad to write code files, there is an encoding format conversion problem.) )such as the error message, we can see that the encoding format caused by the error, the solution is to modify the encoding for
-safe capabilities based on C, and the following are the gender enumeration types defined in C #:
public enum Sex {
Male,
Female,
}
Java does not support enum data types, and Java believes that C provides an enum that is not type-safe, and typically uses a design pattern c
class?
AccordingEnumAndEnum classCan be determined based on the requirements for constant types.EnumOrEnum class.
Applicable to the following scenariosEnum:
The constant type is used for internal representation and is not used to display the name.
A constant value does not need to provide additional attributes. For example, you only need to know the country code, and do not need to obtain o
Java hidden box operation-enum and hidden box operation enum
Enum, which is an enumeration type, has a similar type in each programming language.
Because it is rarely used, every time I see enum, it will be daunting, because its syntax is really "not playing as usual!
The
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.