If you just talk about static inner classes, you can think of them as just top-level classes parasitic in a class. They have nothing to do with each other, but you need to bring the external class name when accessing them
Similarly, if it is a static field in a certain class, you can think of it as just a variable that is parasitic in a class. It has nothing to do with the class it is in. You just need to bring the class of the parasitic class if you want to access it. name, and this variable has one and only one instance in the virtual machine. All Class.static returns this object, and all operations are only for this object. Even if you create an object of its parasitic class and then destroy it, it will not work with it. It’s okay
First of all, the static inner class does not have any dependency on the outer class that wraps it (unlike members, methods, anonymous inner classes). They are essentially two independenttop-level classes, but the static inner class uses the outer class namespace. In other words, static inner classes can be used like ordinary top-level classes, such as OutClass.InnerStaticClass. At the same time, since the static inner class is a member of the outer class, you can use the access modifier to modify its visibility: public protected private package visible
I have never heard of the concept of "static inner class". There are only three usage scenarios of static, namely static variables, static methods and static blocks [Static variables]
When an object is created, member variables are stored in the heap, and static member variables are stored in the method area together with class information, not in the heap. There is only "one copy" of static member variables of a class (stored in method area), regardless of how many objects the class creates.
【Static method】
Static-modified methods do not need to operate on certain objects. The operation results are only related to the input parameters. They can be directly referenced by the class name when calling, and the this keyword cannot be used.
【static block】
static block is a code block belonging to a class. The code block executed during class loading (before creating the object) is only executed once and can be used to load static resources (images, audio, etc.) in the software.
The above objects are all loaded in the method area as the class is loaded, and there is only one copy. It seems that you are talking about the analysis of Java memory model. If you are interested, read this article and spread the word.
If you just talk about static inner classes, you can think of them as just top-level classes parasitic in a class. They have nothing to do with each other, but you need to bring the external class name when accessing them
Similarly, if it is a static field in a certain class, you can think of it as just a variable that is parasitic in a class. It has nothing to do with the class it is in. You just need to bring the class of the parasitic class if you want to access it. name, and this variable has one and only one instance in the virtual machine. All Class.static returns this object, and all operations are only for this object. Even if you create an object of its parasitic class and then destroy it, it will not work with it. It’s okay
First of all, the static inner class does not have any dependency on the outer class that wraps it (unlike members, methods, anonymous inner classes). They are essentially two independenttop-level classes, but the static inner class uses the outer class namespace. In other words, static inner classes can be used like ordinary top-level classes, such as OutClass.InnerStaticClass. At the same time, since the static inner class is a member of the outer class, you can use the access modifier to modify its visibility: public protected private package visible
I have never heard of the concept of "static inner class". There are only three usage scenarios of static, namely static variables, static methods and static blocks
[Static variables]
【Static method】
【static block】
The above objects are all loaded in the method area as the class is loaded, and there is only one copy. It seems that you are talking about the analysis of Java memory model. If you are interested, read this article and spread the word.
JVM memory model: http://blog.csdn.net/u0121526...