public class sample1
{
private static Map m = new HashMap();
//....
//.....
//
public void fun(String str1, String str2, sample2 s )
{
String str = str1 + str2 + s.getName();
String value = m.get(str);
}
}
public class sample2
{
private String name;
// ......
// ........
pubic String getName()
{
return name;
}
}
这里我的问题是在堆或堆栈中存储了str1,str2和s(sample2对象)的变量(函数fun的参数)究竟在哪里?
答案 0 :(得分:3)
str1和str2永远不会出现任何同步失败,因为这些变量是字符串,字符串类在Java中是不可变的。