<分区>
下面是我的一位 friend 在讨论中提出的问题,但我们都不知道实际答案是什么。
public class Test {
static int i = 5;
static String str = "Welcome";
static Map<String, String> map = new HashMap<>();
}
在目标代码中,当创建JVM实例并去创建所有三个对象时,它在哪里创建它
- Inside memory/metadata area
- Inside heap area
我们知道,内存区
保存了类相关的所有数据(包括静态引用),堆区
保存了类的所有实例变量。
但是对于上面的类
- int variable is created(We assume that it will be created in method area
- Not sure about the other two object(String and HashMap)
如果我们有任何误解,请纠正我们,并帮助我们理解这些变量将如何存储在 java 中