java虚拟机实例中 静态对象 只有一个吗?
阿神
阿神 2017-04-18 10:32:45
0
3
429

一个静态内部类, 当他的外部类的对象 销毁后,静态内部类 对象 还存在内存中 ,
一个类的对象,无论创建销毁多少次 ,静态内部类的静态对象还是只有那一个,修改的时候,只是在原来的静态对象上,进行修改? 这样理解对不对..

阿神
阿神

闭关修行中......

reply all(3)
巴扎黑

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

PHPzhong

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.

JVM memory model: http://blog.csdn.net/u0121526...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template