gpt4 book ai didi

java - java中会在哪里创建对象

转载 作者:行者123 更新时间:2023-11-30 10:26:56 27 4
gpt4 key购买 nike

<分区>

下面是我的一位 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 中

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com