gpt4 book ai didi

java - Java中的静态方法

转载 作者:行者123 更新时间:2023-12-01 07:00:03 26 4
gpt4 key购买 nike

查看一些 java 代码,这似乎不对。对我来说,看起来每次你调用projects时,你都会得到一个新的hashmap,所以这个说法总是错误的

projects.get(soapFileName) != null

似乎应该有一个支持字段

public static HashMap<String,WsdlProject> projects = new HashMap<String,WsdlProject>();

public Object[] argumentsFromCallSoapui(CallT call, Vector<String> soapuiFiles, HashMap theDPLs,int messageSize)
{
try {
for (String soapFileName:soapuiFiles){
System.out.println("Trying "+soapFileName);
WsdlProject project ;
if (projects.get(soapFileName) != null){
project = projects.get(soapFileName);
} else {
project = new WsdlProject(soapFileName);
projects.put(soapFileName,project);
}
}
} ...
}

最佳答案

不。在 Java 中,静态变量仅初始化一次。

因此,该行只会被调用一次。

public static HashMap<String,WsdlProject> projects = new HashMap<String,WsdlProject> ();

关于java - Java中的静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1069343/

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