<分区>
Possible Duplicate:
Is Java pass by reference?
因此请考虑以下两个示例及其各自的输出:
public class LooksLikePassByValue {
public static void main(String[] args) {
Integer num = 1;
change(num);
System.out.println(num);
}
public static void change(Integer num)
{
num = 2;
}
}
输出:
1
public class LooksLikePassByReference {
public static void main(String[] args) {
Properties properties = new Properties();
properties.setProperty("url", "www.google.com");
change(properties);
System.out.println(properties.getProperty("url"));
}
public static void change(Properties properties2)
{
properties2.setProperty("url", "www.yahoo.com");
}
}
输出:
www.yahoo.com
为什么会是 www.yahoo.com?
我觉得这不像是传递值。