([{\^-$|]})?*+.銆傛敞鎰忥紝鍦ㄦ煇浜涙椂鍊欒繖浜涚壒孌婄殑瀛楃騫朵笉涓瀹氫唬琛ㄧ壒孌婂惈涔夛紝渚嬪 - 鍦╗a-c]涓槸鍏冨瓧絎︼紝浣嗗湪 a-c 鍒欎笉琛ㄧず鐗規畩鍚箟銆備笉榪囦笂闈㈡病鍒楀嚭鐨勫瓧絎﹀垯涓瀹氫笉浼氫唬琛ㄧ壒孌婂惈涔夈?br />
2銆佸彲浠ュ鍏冨瓧絎﹁繘琛岃漿涔夛紝涓昏鏈変袱縐嶆柟娉曪細
[abc] | a, b, or c (simple class) |
[^abc] | Any character except a, b, or c (negation) |
[a-zA-Z] | a through z, or A through Z, inclusive (range) |
[a-d[m-p]] | a through d, or m through p: [a-dm-p] (union) |
[a-z&&[def]] | d, e, or f (intersection) |
[a-z&&[^bc]] | a through z, except for b and c: [ad-z] (subtraction) |
[a-z&&[^m-p]] | a through z, and not m through p: [a-lq-z] (subtraction) |
. | Any character (may or may not match line terminators) |
\d |
A digit: [0-9] |
\D |
A non-digit: [^0-9] |
\s |
A whitespace character: [ \t\n\x0B\f\r] |
\S |
A non-whitespace character: [^\s] |
\w |
A word character: [a-zA-Z_0-9] |
\W | A non-word character: [^\w] |
Enumerated types have no public constructor. The only instances of an enumerated type are those declared by the enum.
Enums are not Cloneable, so copies of the existing instances cannot be created.
Enums implement java.io.Serializable so they can be serialized, but the Java serialization mechanism handles them specially to ensure that no new instances are ever created.
Instances of an enumerated type are immutable: each enum value retains its identity. (We'll see later in this chapter that you can add your own fields and methods to an enumerated type, which means that you can create enumerated values that have mutable portions. This is not recommended, but does not affect the basic identity of each value.)
Instances of an enumerated type are stored in public static final fields of the type itself. Because these fields are final, they cannot be overwritten with inappropriate values: you can't assign the DownloadStatus.ERROR value to the DownloadStatus.DONE field, for example.
By convention, the values of enumerated types are written using all capital letters, just as other static final fields are.
Because there is a strictly limited set of distinct enumerated values, it is always safe to compare enum values using the = = operator instead of calling the equals() method.
Enumerated types do have a working equals( ) method, however. The method uses = =finalso that it cannot be overridden. This working equals( ) method allows enumerated values to be used as members of collections such as Set, List, and Map. internally and is
Enumerated types have a working hashCode() method consistent with their equals( )equals(), hashCode( ) is final. It allows enumerated values to be used with classes like java.util.HashMap. method. Like
Enumerated types implement java.lang.Comparable, and the compareTo() method orders enumerated values in the order in which they appear in the enum declaration.
Enumerated types include a working toString( ) method that returns the name of the enumerated value. For example, DownloadStatus.DONE.toString( ) returns the string "DONE" by default. This method is not final, and enum types can provide a custom implementation if they choose.
Enumerated types provide a static valueOf( ) method that does the opposite of the
default
toString( ) method. For example,
DownloadStatus.valueOf("DONE") would return
DownloadStatus.DONE.
Enumerated types define a final instance method namedordinal()that returns an integer for each enumerated value. The ordinal of an enumerated value represents its position (starting at zero) in the list of value names in the enum declaration. You do not typically need to use the ordinal( ) method, but it is used by a number of enum-related facilities, as described later in the chapter.
Each enumerated type defines a static method named values( ) that returns an array of enumerated values of that type. This array contains the complete set of values, in the order they were declared, and is useful for iterating through the complete set of possible values. Because arrays are mutable, the values( ) method always returns a newly created and initialized array.
Enumerated types are subclasses of java.lang.Enum, which is new in Java 5.0. (Enum is not itself an enumerated type.) You cannot produce an enumerated type by manually extending the Enum class, and it is a compilation error to attempt this. The only way to define an enumerated type is with the enum keyword.
It is not possible to extend an enumerated type. Enumerated types are effectively final, but the final keyword is neither required nor permitted in their declarations. Because enums are effectively final, they may not be abstract.
Like classes, enumerated types may implement one or more interfaces.聽
ActionListener MouseMotionListener3銆佷簨浠剁洃鍚師鐞嗭細
AdjustmentListener MouseWheelListener
FocusListener WindowListener
ItemListener WindowFocusListener
KeyListener WindowStateListener
MouseListener
甯哥敤鐨勯傞厤鍣ㄧ被錛?br />FocusAdapter MouseMotionAdapter
KeyAdapter WindowAdapter
MouseAdapter
desktop | Background color of desktop |
activeCaption | Background color for captions |
activeCaptionText | Text color for captions |
activeCaptionBorder | Border color for caption text |
inactiveCaption | Background color for inactive captions |
inactiveCaptionText | Text color for inactive captions |
inactiveCaptionBorder | Border color for inactive captions |
window | Background for windows |
windowBorder | Color of window border frame |
windowText | Text color inside windows |
menu | Background for menus |
menuText | Text color for menus |
text | Background color for text |
textText | Text color for text |
textInactiveText | Text color for inactive controls |
textHighlight | Background color for highlighted text |
textHighlightText | Text color for highlighted text |
control | Background color for controls |
controlText | Text color for controls |
controlLtHighlight | Light highlight color for controls |
controlHighlight | Highlight color for controls |
controlShadow | Shadow color for controls |
controlDkShadow | Dark shadow color for controls |
scrollbar | Background color for scrollbars |
info | Background color for spot-help text |
infoText | Text color for spot-help text |
Operators |
Associativity |
---|---|
Left to right |
|
! ~ ++ -- + (unary) 鈥?/tt> (unary) () (cast) new |
Right to left |
* / % |
Left to right |
+ - |
Left to right |
Left to right |
|
< <= > >= instanceof |
Left to right |
== != |
Left to right |
& |
Left to right |
^ |
Left to right |
| |
Left to right |
&& |
Left to right |
|| |
Left to right |
?: |
Right to left |
= += -= *= /= %= &= |= ^= <<= >>= >>>= |
Right to left |
Type |
Storage Requirement |
Range (Inclusive) |
---|---|---|
4 bytes |
鈥?,147,483,648 to 2,147,483,647 (just over 2 billion) |
|
short |
2 bytes |
鈥?2,768 to 32,767 |
long |
8 bytes |
鈥?,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
byte |
1 byte |
鈥?28 to 127 |
Type |
Storage Requirement |
Range |
---|---|---|
4 bytes |
approximately 鹵3.40282347E+38F (6鈥? significant decimal digits) |
|
double |
8 bytes |
approximately 鹵1.79769313486231570E+308 (15 significant decimal digits) |
Core Java 2 Volume I - Fundamentals, Seventh Edition
by Cay S. Horstman, Gary Cornell