import java.util.HashMap;
import java.util.Map;
public class class1 extends Thread{
public Map<String,String> hashMap;
public int value = 1;
public static void main(String[] args) {
// TODO 自动生成的方法存根
new class1();
}
public class1(){
hashMap = new HashMap<String,String>();
this.start();
}
public void run(){
hashMap.put("a", "123");
hashMap.put("b","242");
hashMap.put("c", "4365");
System.out.println("class2修改前:" + value);
new class2(value,hashMap);
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
if(hashMap.containsKey("d")){
System.out.println("true");
System.out.println("class2修改后:" + value);
}else{
System.out.println("false");
}
}
}
import java.util.Map;
public class class2 extends Thread{
private Map<String,String> hashMap;
private int value = 0;
public class2(int value,Map<String,String> hashMap){
this.setValue(value);
this.hashMap = hashMap;
this.start();
}
public void run(){
System.out.println(" class2修改前:" + value);
setValue(3);
System.out.println(" class2修改后:" + value);
hashMap.put("d", "asd");
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}