gpt4 book ai didi

java - Java中全局变量的创建顺序

转载 作者:行者123 更新时间:2023-12-01 18:27:47 25 4
gpt4 key购买 nike

是否保证以下实例按顺序创建?例如,我们可以假设 B 总是在 E 之前创建吗?

public class Example {
public static final Integer A = new Integer(1);
public static final Integer B = new Integer(2);
public static final Integer C = new Integer(3);
public static final Integer D = new Integer(4);
public static final Integer E = new Integer(5);
public static final Integer F = new Integer(6);
}

最佳答案

只要确认语句按顺序执行,很可能会按顺序创建实例/对象,或者按顺序分配内存。

此外,正如 Kevin Krumwiede 所指出的那样,您的代码甚至无效,您缺少所有变量/引用的数据类型声明...

public static final Integer A = new Integer(1);
public static final Integer B = new Integer(2);
public static final Integer C = new Integer(3);
public static final Integer D = new Integer(4);
public static final Integer E = new Integer(5);
public static final Integer F = new Integer(6);

关于java - Java中全局变量的创建顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25454063/

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