Http://blog.csdn.net/wizardmly/article/month/2010/12
Java basics enhance video learning:
I. knowledge points:
21. comprehensive example of member variable reflection: Change "B" in the string corresponding to all string type member variables in any object to "".
(1) p124: When the referenced values of the two objects compared have only one copy, we can use = for comparison.
(2) Use getfields () to obtain all the fields in the bytecode and return them using an array of objects in the field class.
(3) The object. GetType () method returns the class bytecode of the object.
22. Reflection of member Methods: reflected to class methods
(1) method indicates a method in the class. Similar to the reflection of member variables, it only corresponds to the fields of the member methods in the class bytecode.
(2) how to obtain a method in the class:
(3) Call method: Method object. Invoke (OBJ, parametertype list), method object execution method invoke call, call method object to the method, and call the Method
If it is OBJ, which overload version method in obj is called, we use parametertype list to match it.
(4) When the method is a static method, the obj in the invoke parameter table of the preceding method does not need an instance object. You can directly change it to null to call this method because the static method does not depend on the object.
23. Reflect the member methods that receive array parameters:
(1) In eclipse, when we need a complete Class Name, select a class name in the program, and then press F2, the complete class name will be obtained.
(2), // 1. If the statement is used directly: mainmethod. invoke (null, new string [] {"111", "222", "333"}); call the main () method
// The compiler will report an error because, in jdk1.5, to be compatible with the call method in jdk1.4, the compiler will unpack the array string [] {...}
// After the array is split, each element in the string [0], string [1], string [2] is automatically split into the corresponding packing type.
// The element is regarded as an array. Each element in the array is a packing type, that is, three arrays.
// 2. When using the following method for output, use string [] {...} as an element of the object [] array. When the compiler detaches an array object,
// The result is string [] {...}.
// Mainmethod. Invoke (null, new object [] {New String [] {"111", "222", "333 "}});
// 3. The array is also a subclass object of the object. When we use the following output, we forcibly convert string [] into an object.
// The compiler will not be able to unpack the package. The entire string [] {...} array is passed to the main () method.
Mainmethod. Invoke (null, (object) New String [] {"111", "222", "333 "});
(3) When running a class, if there is a main () function in the class, we can pass a string array string [] ARGs like this method, and the parameter is named args. In the main () method
, We can use the ARGs parameter name to call the string array passed to us. In particular, when this string array is a complete class name, we can use this parameter
Obtain the bytecode of the class to obtain the various components of the bytecode.
(4) how to give the string [] ARGs parameter of the main () method in the class, so that the string can be directly called in the main () method.
In the Java program area, right-click --> Run as --> RUN configuration --> in the argument column, enter the real parameters to be passed, this parameter is passed to the MAI () method.
24. Relationship between arrays and objects and their reflection types:
(1) array reflection: arrays are also a type. Each array with the same element type and dimension belongs to the same class (bytecode ),.
(2) When returning the bytecode name of the array object, we get "[I". The brackets "[" indicate the number of "[", the array "I" that represents the number of dimensions represents an integer.
You can refer to related knowledge in the getname () method of class.
(3) to obtain the superclass of a class, we use the method: Object Name. getclass (). getsuperclass (). getname ().
We use the (3) method for array type variables, and we get that their superclass are all objects.
(4) how to print all elements of the array directly: Use the method aslist (): arrays in the arrays class. aslist ("array name"), then we will get the Value List of this array.
(5) differences between int [] and string [] processed by arrays. aslist:
The string objects in the string [] array are all object objects, while the int element in the int [] array is only a basic type and is not an object.
The real parameter passed to aslist (). If it is a string [] array, each element in the array is an object. If it is an int [] array, all elements in the array are of a basic type, not an object. In jdk1.4, the real parameter passed to the aslist () method is an array of object []. In jdk1.5 and later versions, variable parameters are used for implementation. When we pass the string [] array to the form parameter, the real parameter is correctly passed to the aslist () method due to the features of the above string. However, when we pass the int [] array to the form parameter, because of the aforementioned features of the int [] array, the parameter is incorrectly transmitted, then the version above jdk1.5 is returned for processing, in this processing, the real parameter int [] will be treated as an object, that is, only the array type and hash code of the object can be returned.
Ii. Problems and gains:
(1) jdk1.4 does not use variable parameters and is introduced in 1.5. In addition, jdk1.5 adds the automatic packing function,
(2) When we call the invoke method according to the jdk1.4 syntax, the parameter list is transmitted using arrays, such as object [] {2}. However, why does the compiler report an error when there are multiple elements of another array, such as {2, 1, 0?
(3) When watching the video, the teacher defined several arrays and then compared them. The code in eclipse does not report an error. However, when I run the code myself, the following error occurs:
Incompatible operand types class <capture #8-? Extends int []> and class <capture #9-? Extends int [] []>
Resolution: I checked the online materials and explained them as follows:
For the variable compiler of the array type, the type is already known during compilation. That is to say, the compiler considers these two types to be different. There is no need for comparison.
It is meaningless for a comparison that is always not established. This compilation error is a new function of JDK 1.6.
The instructor uses the jdk1.5 version, and I use version 1.6.