我觉得我很菜,因为我要问这个问题——当我将以下Set传递到我的方法并将其指向一个新的HashSet时,为什么它仍然是EmptySet?是因为局部变量在堆栈上分配,所以当我退出方法时,我的new就被清除了吗?我该如何实现功能等效性呢?
import java.util.HashSet;
import java.util.Set;
public class TestMethods {
public static void main(final String[] args) {
final Set<Integer> foo = java.util.Collections.emptySet();
test(foo);
}
public static void test(Set<Integer> mySet) {
mySet = new HashSet<Integer>();
}
}