Java:静态字段在内存中居住在哪里? [英] Java: where do static fields live within the memory?

查看:551
本文介绍了Java:静态字段在内存中居住在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们将对象存储在对象的静态字段中,JVM如何为其分配内存?它是否住在隐式(不知道如果我使用正确的词)类对象?静态字段与对象字段有何区别?

If we store objects in static fields of an object, how does the JVM allocate the memory for it? Does it live within "implicit"(not sure if I am using the right word) class object? How are static fields different from object fields?

推荐答案

静态字段是类变量,并且在该类的所有实例之间共享。实例变量(或对象字段,我认为你是指它们)属于类的单个实例,不共享。

Static fields are class variables, and are shared amongst all instances of that class. Instance variables (or object fields as I think you are referring to them as) belong to individual instances of a class and are not shared.

至于它们存储在何处内存将基于JVM的实现,没有理由需要两个不同的JVM来按规范将它们存储在同一位置(据我所知 - 至少应该在这里插入适当的规格表链接)。

As for where they are stored in memory is going to based on the implementation of the JVM and there is no reason two different JVMs would be required to store them in the same place by specification (to the best of my knowledge at least - should insert appropriate spec sheet link here).

这篇关于Java:静态字段在内存中居住在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆