为什么有人在方法中对字段变量进行新引用?

public class Foo {
    int mFoo[] = {1, 2, 3};

    void method() {
        int foo[] = mFoo; // WHY not just use mFoo?

        print(foo[0]); // WHY not just use mFoo?
    }
}

最佳答案

例如,如果在代码的其他位置更改mFoo的值,则可能是一个好主意。特别是在多线程环境中,您将要确保仍在处理正确的数据。

10-04 19:20