1
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;
             }
}

在这里,我的问题是变量(函数 fun 的参数)如 str1、str2 和 s(sample2 对象)究竟存储在堆还是堆栈中?

4

1 回答 1

3

You will never have any synchronization failure with str1 and str2, because those variables are strings, and the string class is immutable in Java.

于 2013-02-01T20:41:15.743 回答