Java 对象引用/拷贝测试

package sample;   

static class Foo {
        public String name = "init";
}
static void test1(final Foo foo) {
        Foo foo1 = foo;
        foo1.name = "100";
}

public static void main(String[] args) {
        Foo foo = new Foo();
        test1(foo);
        System.out.println(foo.name);
}
输出结果为100,而不是init


发表于:2018-05-25 15:14:40

原文链接(转载请保留): http://www.multisilicon.com/blog/a25331955.html

友情链接: MICROIC
首页