1. Enumeration
* Create an enumeration class
Public Enum grade {
A, B, C, D, E;
}
* Use an anonymous internal class
Enum grade {
A ("100-90 "){
Public String tolocalstring () {return "";}
}
}
* Private constructor
A ("100-90 ")
Private string value;
Private grade (string value ){
System. Out. println ("value" + value );
This. value = value;
}
Public String getvalue () {return value ;}
2. Traverse
* Normal Traversal
For (INT I = 0; I <list. Size (); I ++)
* Traversal in normal mode, using the iterator
Iterator <string> it = List. iterator ();
While (it. hasnext ())
* Use the enhanced for loop to use generics
For (string STR: List)
* Use an enhanced for loop without Using Generics
For (Object STR: List)
* Use an enhanced for loop. When the array is stored, the JavaBean
For (person: Persons)
3. variable parameters
Public static integer sum (integer... arrs)
4. Reflection
* call the class attribute of a class (no call method required, better performance)
class clazz = person. class;
* call the getclass () method of an object
person = new person ();
class clazz = person. getclass ();
* use the forname (classname) Static Method of class
class clazz = Class. forname ("CN. itcast. reflect. person ");
* Call method
class [] parametertypes = {Java. lang. string []. class };< br> method = clazz. getmethod ("Main", parametertypes);
string [] ARGs = {"AA", "BB" };< br> method. invoke (person, new object [] {ARGs});
* obtain a field
Field field = clazz. getdeclaredfield ("Grade");
* obtain the field value
field. get (person)
* set the field value
field. set (person, "N");
* Get object
Object OBJ = clazz. newinstance ();
person = (person) OBJ;
* Get constructor
class [] parametertypes = {Java. lang. string. class, Java. lang. integer. class };< br> constructor = clazz. getconstructor (parametertypes);