reflection
Why should there be reflection?
- At runtime, reflection can be used when certain conditions are required to determine which class of objects to use.
-
Strategic mode (flexible)
abstract BaseStrategy.excute()
` `'abstract basestrategy.excute (){// Implement a strategy}Copy the code
-
- Strategies: AStrategy, BStrategy, CStrategy
-
Class personClass = Class.forName("com.data.muse")
Class personClass1 = Class.forName("com.data.muse")
PersonClass and personClass1 are the same
-
How many ways can I get a class object?
- getClass
Class class1 = person.getClass()
- class
Class class2 = Person.class()
- class.forName
Class class3 = Class.forName(com.xxx)
-
How do I get an object from a class file
-
For the class
Class personClass = Class.forName(com.person)
-
Acquired construction method
Constructor < Person > Constructor. = personClass getConstructor () / / get the Constructor
Person Person = constructive.newinstance () // Initializes a Person object
-
Get the attributes of the Person Class of the Field object through the Class object
Filed nameFiled = personclass. getFiled ("name") // Get the name attribute of the class
-
Field is operated to obtain the property value
String name = String.valueOf(nameFiled.get(person))
-
What’s BeanUtil for
In practice
1. Individual services and micro-services (vertical segmentation) 2. Hierarchical division of services (horizontal segmentation)Copy the code
-
Reflection allows you to assign an object’s property value to another object
The container
ArrayList: Essentially an array
Add: Capacity expansion: Before adding, check whether the length is sufficient and whether the capacity needs to be expanded
1. The binary of the old length is shifted one bit to the right, equal to 1/2 of the original length, plus the original length 2. If the new length still cannot meet the minimum expansion capacity required, the new length is changed to the minimum expansion capacityCopy the code
Remove: {“a1″,” A2 “,” A3 “,”a4”} For example, delete A2
Size-index -1 4-1-1=2 2. Call the System. arrayCopy (old array, delete element index+1, old array) methodCopy the code
LinkedList
Get a Node
add:
get
The index is in the first half or the second half, and then the for loop iterates until the last one is that value
remove:
All operations on arrays are checked out of boundsCopy the code
Disconnect the front and rear nodes of the node to be deleted