Summary of some important knowledge points reviewed in December
- The data class in kotlin is only used as a data class, and does not encapsulate other logical operations. "null" can also have toString().
- The final field of the Java inner class, from the decompilation results, is essentially to eliminate data inconsistency. Because what is passed is actually a copy rather than the value or the object itself, just like a method passing a parameter, the original value or object reference cannot be changed in the method. If it is not final, it seems that the external value or reference can be successfully changed in the inner class, but in fact there is no. In order to prevent this from happening, locate the final, in fact, a class with a constructor will be generated after compilation , the value or reference in the local method (final modification) is passed in, as well as the reference of the external object. Like method parameter passing, modifying the incoming parameter will not affect the original value. After jdk 1.8, it is not necessary to be final, but the principle is still the same, except that it is modified by jvm.
Look at an example: prove that the reference passed to the class is the same as the method, it is just a copy of the same name, but belongs to a different class or method , changing it will not affect the original, whether it is an inner class or a method, it is the same.
public class TestClass {
public static void main(String [] args) {
A a = new A();
System.out.println("第一个A:"+a.getMsg());
B b = new B(a);
System.out.println("第二个A:"+b.getMsg());
System.out.println("第一个A是否被修改:"+a.getMsg());
}
}
class A{
String msg ="AAA";
String getMsg() {
return msg;
}
void setMsg(String m) {
this.msg =m;
}
}
class B{
A aa;
public B(A a) {
a = new A();
a.setMsg("Anthor A");
aa = a;
}
String msg ="BBB";
String getMsg() {
return msg+aa.getMsg();
}
void setMsg(String m) {
this.msg =m;
}
}
输出第一个A:AAA
第二个A:BBBAnthor A
第一个A是否被修改:AAA
- Java ThreadLocal objects. Use this class to reference the same object in different threads, but have different data stores. Via the get() set() method. The reason is that each thread has a ThreadLocalMap object (not a Map, which maintains an Entry[] with a capacity of 16 and a name of table[]). When calling set(), the current thread is obtained first, and then the map is obtained. If it is empty, instantiate the map, pass in the current sThreadLocal object, generate a specific array index i, then use sThreadLocal as the key, put it into the entry together with the value, and then put it into a specific array. When calling get(), the placed value is obtained through sThreadLocal. If no set() returns null. That is to say, a thread can put 16 values associated with different ThreadLocal objects. In Android, it is not a Map, but a localValues object. Inside this object is an Object array, also called table[], which is stored in threadLocal at a specific index, and then stores the value at its next index.
- In Android, Looper.prepare() obtains the Looper instance, which holds the thread and messageQueue fields, which are assigned and instantiated during initialization. The Looper is held in the Handler. When instantiated, the assignment is passed in or the Looper stored in the thread is obtained through the sThreaLocal object. If not, an exception will be thrown. That is to say, before using the child thread handler, you must pass in or initialize the Looper object to associate it with the current thread. The message also holds unexposed target(Handler) and callback(Runable) references. After the message is sent, the sentMessageAtTime() is finally called, and the dispatch message method of the message queue is called to the queue, and then it is taken out and processed according to the target. See the relevant source code for more information.
- RecyclerView has a new SnapHelper abstract class, and there are two implementation classes that can achieve a ViewPager-like effect. LinearSnapHelper and PageSnapHelper. Using code similar to ItemTouchHelper is simple.
- Programming and basic use of Camer class cameras. Customize a SurfaceView to implement the SurfaceHolder interface, the PreViewCallbak interface. Get the camera instance in the Activity, pass in the SurfaceView, and release the camera in time (remove all interfaces first, remove the View, and finally release. After initializing the camera parameters in the View's Surface creation monitor, set the camera to display it to the holder and startPreview. You can also Set up camera monitoring and face detection monitoring as appropriate).
- Java multi-threaded concurrent producer-consumer problem. In order to avoid exceptions caused by the unsynchronization of producers and consumers, it is necessary to lock the shared object (that is, the buffer pool between producers and consumers). Both parties call while() when the buffer pool is not empty or full. Continuously take out or put data from the buffer pool until the condition is not satisfied, call shareObject.wait(), call shareObject.notifty() before wait() to wake up other threads. Note always use whlie() instead of if() . - The Java runtime data area is divided into method area (including constant pool), program counter, Java heap, Java stack (Native Stack and JVM Stack). The method area and heap Heap are shared by threads, while others are independent of threads. The call of each method of each thread is a pop-up and push operation. When the dynamically expanded stack exceeds the maximum depth, StackOverflow occurs. If there are too many recursion times (tail recursion is avoided), when the stack is expanded, there is insufficient memory and OOM.
- For related usage of Glide, see Guo Lin's blog for details. http://blog.csdn.net/guolin_blog/article/details/78582548 .
- General usage of GPUImage. gpuImage.setBitmap() gpuImage.setFilter() gpuImage.getBitmapWithFilterApplied(). Blend filters using GPUImageGroupFilters and updateFilters() then getBitmap() .
- Send it here for now. = =