在Java中,我该如何做以下操作:
Foo bar = new Foo();
Foo a = bar;
Foo b = bar;
bar = null;//will only set bar to null. want to set value of bar to null rather than the reference to null.
是否可以只通过访问bar
来将变量bar
、a
和b
(它们都是对bar
的引用)设置为null?如果可以,请有人解释一下如何操作。