Enum class:
1. Custom enumeration Classes
1. Provide the properties of the class, declared private final
2. Attribute declared final, initialized in constructor , privatized constructor , guarantees that its object cannot be created outside the class
3. Calling properties through a public method
4. Create an object of an enumeration class: Declare the object of the class as public static final
2. Keyword Enum definition enum class
Common methods in 1.enum
(1)values (); Returns all objects of the entire enumeration type as an array
Season[] seasons = Season.values ();//Returns an array
(2)valueOf (String name); An incoming parameter is a property name of an enumeration class that returns an object of that property, or an exception is reported
String str = "SPRING";
Season sea = season.valueof (str);//spring ("Spring" and "Spring Blossoms")
3. How to enable an enumeration class to implement an interface
1. Let the class implement this interface, the object of the class shares the abstract method of the same set of interfaces
2. Having each object of a class implement an abstract method of the interface, and then invoke the overridden abstract method through the object of the class, performs differently.
Enum season{ Spring ("Spring", "springtime"), SUMMER ("SUMMER", "summer scorching"), AUTUMN ("AUTUMN", "crisp"), WINTER ( "Winter", "Snowy"); Private final String Seasonname; Private final String Seasondesc; Private Season (String seasonname, String seasondesc) { this.seasonname = seasonname; This.seasondesc = Seasondesc; } Public String Getseasonname () { return seasonname; } Public String Getseasondesc () { return seasondesc; }}
Note: Annotation
1.JDK built-in basic annotation type (3)
@Override: Qualifies overriding the parent class method, which can only be used for methods
@Deprecated: Used to indicate that a program element (class, method, and so on) is obsolete
@SuppressWarnings: Suppress Compiler warnings
2. Custom annotation Types
Take Suppresswarnings as an example to create
3. Annotate annotations (4) (meta-annotations)
Retention
Rarget
Documented
Inherited
Java Basics-Enumerations and annotations