Java哈希集<;字符串>';s contains()不执行';eclipse热转载后不匹配

Java哈希集<;字符串>';s contains()不执行';eclipse热转载后不匹配,java,eclipse,Java,Eclipse,当我修改代码时,eclipse将使用jetty重新发布web应用程序。具有相同字符串的Hashset.contains()返回false 代码: private static HashSet code=new HashSet(); 公共字符串f1(){ 字符串a=getCode(); 代码.添加(a); 返回;//返回webclient(浏览器)。 } 公共无效f2(字符串b){ //b从浏览器中读取,与a相同 代码.包含(b) //它返回false!热重发布后 ... } HashMap的函

当我修改代码时,eclipse将使用jetty重新发布web应用程序。具有相同字符串的Hashset.contains()返回false

代码:

private static HashSet code=new HashSet();
公共字符串f1(){
字符串a=getCode();
代码.添加(a);
返回;//返回webclient(浏览器)。
}
公共无效f2(字符串b){
//b从浏览器中读取,与a相同
代码.包含(b)
//它返回false!热重发布后
...
}
HashMap的函数getEntry在debug中返回null,看起来像条目e=table[indexFor(hash,table.length)];e是空的


那么,它是如何发生的呢?

我认为代码是一个静态变量,它将在类加载器加载类时初始化,因此当您重新发布应用程序时,代码将被重置。您最好将项目重新添加到代码映射中

private static HashSet<String> code = new HashSet<String>();
public String f1(){ 
    String a = getCode();
    code.add(a);
    return a; //return to webclient(Browser).
}
public void f2(String b){
    //b is read from Browser, same as a
    code.contains(b)
    // it return false! after hot reepublish
    ...
}