java enum class example

Read about java enum class example, The latest news, videos, and discussion topics about java enum class example from alibabacloud.com

How to use objects in a running class in another class in Java, for example.

1 Packagetimers;2 3 ImportJava.util.Timer;4 ImportJava.util.TimerTask;5 6 /*7 * Mainly want to use the object of this class in another class, how to use it? How to pass the same instance object8 */9 Public classTimerdemo {Ten Public Static voidMain (string[] args) { OneTimer T =NewTimer (); AT.schedule (NewMyTask (t), 3000); - } - } the - classMyTaskextendsTimerTask { //In order to use the T o

A comprehensive interpretation of enumeration types in Java use of enum _java

on the values in the enumeration, and the encapsulation is better. InstanceLet's first define a simple enumeration (this is just an example of a simple definition of 3 variables): public enum Sqltypeenum { INSERT, UPDATE, DELETE, SELECT } After parsing the SQL, we get a token, how do we get this token enumeration? This gets: String token = "select"; Sqltypeenum sqltypeenum

Java enumeration enum and application: enumeration implements Singleton mode

Enumeration as a general language concept, until the birth of Java5 has to say a bit strange, so far many programmers still prefer to use static final form to name constants without using, in general, Java programmers in this way to implement enumerations:Class enumbyclass{public static final int red=0; public static final int green=1; public static final int blue=2;}An enumeration implemented in this way is also called an int enumeration pat

Java enum Enumeration

; PrivateSex4 (Stringsex ){ This. Sex = sex; } PublicString toString (){ ReturnSex; } } In this way, you can use the Sex4 type to ensure that the gender can be a BOY or GIRL. For example, the following function definition: PublicvoidOutSex (Sex4sex ){ System.Out. Println (sex ); } But now the problem comes again. We only need to use two constants, but we need to write so many lines of code (when defining Sex4). Is there a simple way? The answer is, of

Enum class (msdn)

enumeration as a bit field. For more information, see flagsattribute.Implemented Interface This class inherits from valuetype and implements icomparable, iformattable, and iconvertible interfaces. Use the convert class for conversion, instead of using the explicit interface member of this class iconvertible.Guidelines for flagsattribute and

Java enum (enumeration) and javaenum

SAT = "Sat"; String SUN = "Sun ";} With enumeration, we can use the following method: public enum WeekEnum { MON, TUE, WED, THU, FRI, SAT, SUN;} Explanation: To create an enumeration type, use the enum keyword, which implies that all created types are subclasses of the java. lang. Enum

Override the ToString () of the class to simplify obtaining the DescriptionAttribute value of enum,

Override the ToString () of the class to simplify obtaining the DescriptionAttribute value of enum,Override the ToString () of the class to simplify obtaining the DescriptionAttribute value of enum. Directory I. Common enum versions Ii. Evolution:

Override the ToString () of the class to simplify obtaining the DescriptionAttribute value of enum,

Override the ToString () of the class to simplify obtaining the DescriptionAttribute value of enum,Override the ToString () of the class to simplify obtaining the DescriptionAttribute value of enum. Directory I. Common enum types Ii. Evolution:

Usage of Enum in Java

1. About Java Enum: Anyone who has studied C/C ++ or other languages should have a slight knowledge of the Enum type. Enum is generally used to represent a group of constants of the same type. Such as gender, date, month, and color. The benefit of using constants for these attributes is obvious. Not only can the single

Java Enum enumeration can also be used this way

", 4); private String name; private int index; Private state (String name, int index) { this.name = name; This.index = index; } Interface Method 1 @Override public String getState () { return this.name; } Interface Method 2 @Override public Void Read () { System.out.println (This.index + ":" + this.name); } }Like using an interface in a generic

What's going on with the Java enum enumeration?

Sex4 ( public staticfinal Sex4 Boy =New Sex4 ("GIRL"); Private Stringsex; Private Sex4 (Stringsex) { this. Sex = Sex ; } public String toString () { returnsex; }}In this way, you can use the SEX4 type to ensure that the gender can be a boy or a girl if you need to use sex elsewhere. For example, a function similar to the following definition: Public void outsex (Sex4sex) { System. out . println (sex);}But now that's the problem,

Java secret:using an enum-to-Build a state machine (Java secret: building an enumeration with enumerations)

Recently in the Hadoop#yarn part of the source code, read the state machine that part of the time, feel the use of ENMU is too flexible, in the concurrent programming network to translate an article, just met an article like this, quickly translated down, rose posture.Original link: http://www.javacodegeeks.com/2011/07/java-secret-using-enum-to-build-state.htmlPeter Lawrey Translator: Chen ZhenyangReviewEnm

Gain an in-depth understanding of enum in Java and Javaenum

Gain an in-depth understanding of enum in Java and Javaenum We can use either the public static final String constant or the enum String constant to represent a limited number of things in a program. In general, the former is simple, but it cannot provide more information. In Java,

[Java] Enum in Java

The introduction of enum from jdk1.5 is actually a special class, which is easy to write. JVM automatically encapsulates a lot of things for you. Package scjp; The compiled Enum (coffeesize above) also generates a coffeesize. Class Decompilation through class assemblyJava

Java Enum (enumeration) Usage Details + Summary

Enum is called enumeration. It is a new feature introduced in JDK 1.5 and is stored in the Java. lang package. The following are some of my experiences and conclusions in using Enum, including: 1. Original interface definition constant 2. syntax (Definition) 3. Common Operations such as traversal and switch 4. Introduction to common methods for

Enum enumeration class | annotation Annotation

Enum enumeration class ① Differences between enumeration classes and common classes:The enumeration class defined by Enum inherits the java. Lang. Enum class by default.The constructor

Java Learning (11): Java lock synchronized, object lock and Class lock example

(intv) One { A synchronized(mysynchronized.class) - { - while(true) the { - System.out.println (v); - } - } + } - + Public voidRun () A { at Printval (val); - } -}View CodeAdditional Lock Examples:1 Public classMysynchronizedextendsThread2 {3 PrivateString name;4 5 PrivateString Val;6 7 Publicmysynchronized (string name, String v)8 {9 This. Name =name;Tenval =v; One } A

Enum right is best placed outside the class

actual call, and the compiler will make an error.For example, the form's calling function is as follows:private void Button1_Click (object sender, EventArgs e) { Testenum testenum = new Testenum ((thefirstenum) random. Next (3), (Thesecondenum) random. Next (3)); MessageBox.Show (Testenum.value); }The constructor was removed from the first Enum section and resumed normal

Deep mastery of Enum in Java

For something that you want to represent a finite kind of thing in a program, generally we can do it in two ways: public static final String constant, and second, using Enum to represent. In general, the former is simple, but not very good to provide more information, and in Java, the enum is very strong, but also more professional. 1. most C-style

Java enumeration (enum) detailed 7 common usage (reprint) __java

GetName () {return name; } public void SetName (String name) { this.name = name; } public int GetIndex () {return index; } public void Setindex (int index) { this.index = index; } } usage Four: Methods of overriding enumerations An example of a ToString () method overlay is given below. The public enum Color {red

Total Pages: 15 1 .... 4 5 6 7 8 .... 15 Go to: Go

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.