Enhanced for Loop)
The so-called "enhanced for loop" mainly targets containers. When this feature is used, developers can
The logic of traversing the container is handed over to the compiler for processing. For example, the following code:
Void cancelall (collection C ){
For (iterator I = C. iterator (); I. hasnext ();){
Timertask TT = (timertask) I. Next ();
TT. Cancel ();
}
}
You can use an enhanced for loop to rewrite it:
Void cancelall (collection C ){
For (Object O: C)
(Timertask) O). Close ();
}
After the compiler determines that object C is a collection sub-object (that is, a container), it will allow the use of an enhanced for Loop
Form, and automatically get the C iterator to automatically traverse each element in C.
As you can see, the above Code still has a forced type conversion (timertask) O). Close ();). In fact
Item features should be generally combined with generic features to maximize the benefits. Combined with generics, the above Code becomes:
Void cancelall (collection C ){
For (timertask task: C)
Task. Cancel ();
}
Public Enum loglevel {
Verbose (2, "verbose", 'V'), // $ NON-NLS-1 $
Debug (3, "debug", 'd), // $ NON-NLS-1 $
Info (4, "info", 'I'), // $ NON-NLS-1 $
Warn (5, "Warn", 'w'), // $ NON-NLS-1 $
Error (6, "error", 'E'), // $ NON-NLS-1 $
Assert (7, "assert", 'A'); // $ NON-NLS-1 $
Private int mprioritylevel;
Private string mstringvalue;
Private char mpriorityletter;
Loglevel (INT intpriority, string stringvalue, char prioritychar ){
Mprioritylevel = intpriority;
Mstringvalue = stringvalue;
Mpriorityletter = prioritychar;
}
/**
* Circular buffer containing the logcat output. This is unfiltered.
* The valid content goes from <code> mbufferstart </code>
* <Code> mbufferend-1 </code>. Therefore its number of item is
* <Code> mbufferend-mbufferstart </code>.
*/
Private logmessage mkernermsg = new logmessage ();
/*
* This below inherited from log. Java
*/
/**
* Returns the {@ link loglevel} Enum matching the specified letter.
* @ Param letter the letter matching a <code> loglevel </code> Enum
* @ Return a <code> loglevel </code> object or <code> null </code> if no match were found.
*/
Public static loglevel getbyletter (char letter ){
For (loglevel mode: values ()){
If (mode. mpriorityletter = letter ){
Return mode;
}
}
Return NULL;
}
How to understand this values?