Java 1.5 Tiger A Developers Notebook [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Java 1.5 Tiger A Developers Notebook [Electronic resources] - نسخه متنی

David Flanagan, Brett McLaughlin

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید








3.2 Declaring Enums Inline


While it's useful to create a

separate enum class, defined in its own
source file, sometimes its also useful to just define an enum, use it, and
throw it away. This is possible through member types.


3.2.1 How do I do that?


Just define the enum within your class, as you would any other member
variable. You might
need a DownloadStatus enum, for example, but only
within a Downloader class:


public class Downloader {
public enum DownloadStatus { INITIALIZING, IN_PROGRESS, COMPLETE };
// Class body
}

Oddly enough, this same code may be written as follows:


public class Downloader {
public static enum DownloadStatus { INITIALIZING, IN_PROGRESS, COMPLETE };
// Class body
}

In this case, the static modifier has been added. This has no effective
change on the enum, as nested enums are implicitly static. In other
words, it's sort of like declaring an interface abstractit's redundant.
Because of this redundancy, I'd recommend against using the static
keyword in these declarations.

NOTE

Examples in the
enum specification
also omit
"static" in nested
declarations.


/ 131